美文网首页
修改navigationBar的阴影线的颜色

修改navigationBar的阴影线的颜色

作者: 大眠兽 | 来源:发表于2016-08-25 16:17 被阅读0次

简单的说,就是用一张纯色的图片来代替阴影线。
那么,直接上代码。

首先获取一个纯色图片

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

好了修改成功。

相关文章

网友评论

      本文标题:修改navigationBar的阴影线的颜色

      本文链接:https://www.haomeiwen.com/subject/hdrasttx.html