iOS 11导航栏底线

时间:2017-09-22 04:36:16

标签: ios xcode navigationbar iphone-x

今天刚刚开始使用Xcode 9和iOS 11,我发现在导航栏底部上方创建了大约3 px的边框线。我在iOS 10中从未见过同样的事情。任何想法如何删除它?要说清楚它不是下面屏幕截图中的iPhone X主页按钮,而是导航栏中的行

iPhone 7 Plus iOS 11 screenshot

1 个答案:

答案 0 :(得分:1)

我找到了答案:导航栏创建的底部阴影线无法直接访问,我必须编写代码替换该阴影的图像。对于遇到同样问题的人来说,这就是代码:

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"11.0")) {
    // Remove navigation bar bottom shadow line in iOS 11
    [self.navigationBar setBackgroundImage:[self generateSinglePixelImageWithColor:[FillrThemeManager sharedInstance].theme.fillViewNavigationBarTintColor] forBarMetrics:UIBarMetricsDefault];
    self.navigationBar.shadowImage = [self generateSinglePixelImageWithColor:[UIColor clearColor]];
}

- (UIImage *)generateSinglePixelImageWithColor:(UIColor *)color {
  CGSize imageSize = CGSizeMake(1.0f, 1.0f);
  UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0f);

  CGContextRef theContext = UIGraphicsGetCurrentContext();
  CGContextSetFillColorWithColor(theContext, color.CGColor);
  CGContextFillRect(theContext, CGRectMake(0.0f, 0.0f, imageSize.width, imageSize.height));

  CGImageRef theCGImage = CGBitmapContextCreateImage(theContext);
  UIImage *theImage;
  if ([[UIImage class] respondsToSelector:@selector(imageWithCGImage:scale:orientation:)]) {
      theImage = [UIImage imageWithCGImage:theCGImage scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
  } else {
      theImage = [UIImage imageWithCGImage:theCGImage];
  }
  CGImageRelease(theCGImage);

  return theImage;
}