美文网首页
去除NavigationBar底部黑线,设置Tabbar背景色

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

作者: Ice丶泽 | 来源:发表于2016-11-02 14:00 被阅读0次

    取消 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)]];
    

    相关文章

      网友评论

          本文标题:去除NavigationBar底部黑线,设置Tabbar背景色

          本文链接:https://www.haomeiwen.com/subject/oyuvuttx.html