-3

今天刚开始使用 Xcode 9 和 iOS 11,我发现在导航栏底部上方大约 3 px 处创建了边框线。我在 iOS 10 中从未见过同样的东西。知道如何删除它吗?为了清楚起见,它不是下面截图中的 iPhone X 主页按钮,而是导航栏中的那一行

iPhone 7 Plus iOS 11 截图

4

1 回答 1

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;
}
于 2017-09-25T00:28:31.673 回答