0

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:

  1. iPhone7plus current deploy under xcode8 iPhone7plus current deploy under xcode8
  2. iPhone8plus in Xcode9

iPhone8plus in Xcode9

  1. iPhone8 in Xcode9

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.

Kevin
  • 477
  • 1
  • 5
  • 13
  • why are u using release. ARC manages memory and releases object when required. – luckyShubhra Oct 21 '17 at 04:54
  • You can customise you navigation bar in storyboard. Refer my previous ans [here](https://stackoverflow.com/questions/34447287/customise-ui-navigation-bar-and-button/34447633#34447633). – luckyShubhra Oct 21 '17 at 05:04
  • This part was done by one of my developer, but he left the team. So, I have to look after this myself now, but I am new to coding. Trying to learn as much as I can now. Since the iOS11 changes, this navigation bar layout is giving me headaches. – Kevin Oct 21 '17 at 05:47
  • I am not sure how to convert the current project to storyboard. – Kevin Oct 21 '17 at 05:48
  • if you can share your view controller class and xib to my mail id , may be i can help. My email id is developershubhra@gmail.com – luckyShubhra Oct 21 '17 at 08:33

0 Answers0