去除NavigationBar底部黑线,设置Tabbar背景色

2016-11-02  本文已影响0人  Ice丶泽

取消 NavigationBar 底部黑线,我查到了一些解决方式,但是在实际的项目中,发现还是这种方式比较简单一些

//这个方法是给 navBar 设置背景颜色
[[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();    
// 结束上下文    
    UIGraphicsEndImageContext();    return theImage;
}

用于设置 TabBar 背景色

[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[self imageWithColor:RGBA(200, 200, 200, 0.7)]];
上一篇下一篇

猜你喜欢

热点阅读