在自定义的tabbar的.m文件中
[self setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor] size:CGSizeMake(SCREEN_WIDTH, TabBarHeight)]];
// 背景颜色处理
self.backgroundColor = [UIColor whiteColor];
UIImage的分类中的颜色转图片的方法
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
if (!color || size.width <= 0 || size.height <= 0) return nil;
CGRect rect = 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();
return image;
}
此时需要注意
[[UITabBar appearance] setTranslucent:YES];
这里如果是YES,_UIBarBackground的颜色就是透明色,如果是NO,_UIBarBackground的颜色就是白色(此处踩了坑)
如果需要透明的tabbar,此处就要设置YES