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