美文网首页iOS开发-tabBarController
iOS开发 TabBar阴影方案

iOS开发 TabBar阴影方案

作者: 嫌疑人zx | 来源:发表于2018-09-27 15:00 被阅读204次

UITabBar自带的效果是一条灰色的细线,设计师希望做成阴影效果,查了一些资料,和设计师一起调了一下,达到了比较理想的效果,把代码分享出来!

效果图如下:

阴影.png

代码示例:

#define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

-(void)setTabBarItemFontColor{
    //tabBar线的颜色
    CGRect rect = CGRectMake(0, 0, KScreenW, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [_BaseTabBarVC.tabBar setBackgroundImage:img];
    [_BaseTabBarVC.tabBar setShadowImage:img];
    
    _BaseTabBarVC.tabBar.layer.shadowColor = RGBColor(213, 213, 213).CGColor;
    _BaseTabBarVC.tabBar.layer.shadowOffset = CGSizeMake(0, -2);
    _BaseTabBarVC.tabBar.layer.shadowOpacity = 0.3;//阴影透明度,默认0
}

相关文章

网友评论

    本文标题:iOS开发 TabBar阴影方案

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