在Appdelegate.m里添加以下方法
// 去除導(dǎo)航條黑線
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc]init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
這樣設(shè)置后,雖然去除了導(dǎo)航欄下方的橫線,但是導(dǎo)航欄變成了透明的了。為了保持界面風格的統(tǒng)一,可以把img改成相應(yīng)的顏色;如下
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;
}
}