Just installed Xcode9 and working on my project. I notice the buttons on the navigation bar are now positioned differently now.
The Pictures below are navigation bar under different spec and Xcode:
- iPhone8 in Xcode9
As you can see, in iPhone7+ in current deploy with previous Xcode, the buttons are correctly positioned on the left and right hand side.
However, when I run in xCode9, the buttons and the logo are slightly indent to the right.
Can anyone help me out how I can get the buttons position correctly to the left and right, and have the logo position correctly in the centre ?
Here are the codes set up for the navigation bar and buttons set up:
UIView * leftNaviNaviButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,delegate.windowWidth, 44)];
[leftNaviNaviButtonView setBackgroundColor:[UIColor grayColor]];
UIBarButtonItem * negativeSpacer = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]autorelease];
negativeSpacer.width = -16;
searchbarBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[searchbarBtn setFrame:CGRectMake(0,0,50,44)];
[searchbarBtn setImage:[UIImage imageNamed:@"search_btn.png"] forState:UIControlStateNormal];
[searchbarBtn.imageView setContentMode:UIViewContentModeScaleAspectFit];
[leftNaviNaviButtonView addSubview:searchbarBtn];
UIImageView * logoImageView = [UIImageView new];
[logoImageView setFrame:CGRectMake((delegate.windowWidth-170)/2,0,170,40)];
[logoImageView setImage:[UIImage imageNamed:@"app_headerlogo.png"]];
[logoImageView setContentMode:UIViewContentModeScaleAspectFit];
[leftNaviNaviButtonView addSubview:logoImageView];
UIButton *advanceSearch = [UIButton buttonWithType:UIButtonTypeCustom];
[advanceSearch setFrame:CGRectMake(delegate.windowWidth-50,0,50,44)];
[advanceSearch setImage:[UIImage imageNamed:@"sear ch_adv.png"] forState:UIControlStateNormal];
[advanceSearch.imageView setContentMode:UIViewContentModeScaleAspectFit];
[leftNaviNaviButtonView addSubview:advanceSearch];
[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:negativeSpacer,[[[UIBarButtonItem alloc] initWithCustomView:leftNaviNaviButtonView]autorelease], nil]];
[leftNaviNaviButtonView release];
Thank you so much in advance.