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
}
网友评论