简单的说,就是用一张纯色的图片来代替阴影线。
那么,直接上代码。
首先获取一个纯色图片
- (UIImage *)imageWithColor:(UIColor*)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }
替换掉navigationBar的ShadowImage
UIImage *image = [self imageWithColor:[[UIColor whiteColor] colorWithAlphaComponent:1]]; ////设置NavBar的背景 [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; ////去除阴影分割线的方法 [self.navigationController.navigationBar setShadowImage:image]; self.navigationController.navigationBar.translucent = NO;
好了修改成功。