美文网首页
去除导航栏下面的横线

去除导航栏下面的横线

作者: Sam129 | 来源:发表于2016-11-17 17:07 被阅读0次

在Appdelegate.m里添加以下方法

// 去除导航条黑线

[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc]init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

这样设置后,虽然去除了导航栏下方的横线,但是导航栏变成了透明的了。为了保持界面风格的统一,可以把img改成相应的颜色;如下

CGSize size = 

UIImage *img = [UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(IPHONE_WIDTH, 1)];

//给UIImage添加的类别

+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size

{

@autoreleasepool {

CGRect rect = CGRectMake(0, 0, size.width, size.height);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context,

color.CGColor);

CGContextFillRect(context, rect);

UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return img;

}

}

相关文章

网友评论

      本文标题:去除导航栏下面的横线

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