取消 NavigationBar 底部黑線,我查到了一些解決方式,但是在實際的項目中,發(fā)現(xiàn)還是這種方式比較簡單一些
//這個方法是給 navBar 設(shè)置背景顏色
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"beijing"] forBarMetrics:UIBarMetricsDefault];
//想要去掉 navBar 底部黑線,主要是這個語句,通過給 navBar 添加陰影效果,使黑線不再顯示。
[[UINavigationBar appearance] setShadowImage:[self imageWithColor:[UIColor clearColor]]];
- (UIImage *)imageWithColor:(UIColor *)color{
// 描述矩形
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
// 開啟位圖上下文
UIGraphicsBeginImageContext(rect.size);
// 獲取位圖上下文
CGContextRef context = UIGraphicsGetCurrentContext();
// 使用color演示填充上下文
CGContextSetFillColorWithColor(context, [color CGColor]);
// 渲染上下文
CGContextFillRect(context, rect);
// 從上下文中獲取圖片
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
// 結(jié)束上下文
UIGraphicsEndImageContext(); return theImage;
}
用于設(shè)置 TabBar 背景色
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[self imageWithColor:RGBA(200, 200, 200, 0.7)]];