设置tabBar顶部线条颜色及阴影
由于此版本暂未自定义tabBar的需求,因此直接写在TabBarController中;
亲测,感觉这样比设置阴影图片效果要好的多!!!
注:参照网上资料以及自己实践当作资料或笔记以备后用
[self.tabBar setShadowImage:[UIImage imageWithColor:HCT_TABBARTOP_LINE size:CGSizeMake(SCREEN_WIDTH, 0.7)]];
self.tabBar.layer.shadowColor = HCT_TABBARTOP_LINE.CGColor;
self.tabBar.layer.shadowOffset = CGSizeMake(0, -5);
self.tabBar.layer.shadowOpacity = 0.5;//阴影透明度,默认0
创建UIImage的分类:
+ (UIImage*)imageWithColor:(UIColor*)color size:(CGSize)size {
if(!color || size.width<=0|| size.height<=0)returnnil;
CGRectrect =CGRectMake(0.0f,0.0f, size.width, size.height);
UIGraphicsBeginImageContextWithOptions(rect.size,NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
returnimage;
}