去除导航栏下面的横线

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

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容