iOS11 UIBarButton职位问题

时间:2017-10-20 16:53:03

标签: ios xcode autolayout uibarbuttonitem navigationbar

刚刚安装了Xcode9并处理我的项目。 我注意到导航栏上的按钮现在的位置不同。

下面的图片是不同规格和Xcode下的导航栏:

  1. iPhone7plus目前在xcode8下部署 iPhone7plus current deploy under xcode8
  2. Xcode9中的iPhone8plus
  3. iPhone8plus in Xcode9

    1. Xcode9中的iPhone8
    2. iPhone8 in Xcode9

      正如您所看到的,在使用之前Xcode的当前部署中的iPhone7 +中,按钮正确定位在左侧和右侧。

      然而,当我在xCode9中运行时,按钮和徽标略微向右缩进。

      任何人都可以帮我解释如何让按钮正确左右摆放,并将徽标位置正确放在中间位置?

      以下是为导航栏设置的代码和设置的按钮:

      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];
      

      提前非常感谢你。

0 个答案:

没有答案