不啰嗦,直接上代碼:
CGRect rect = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[tabbar.tabBar setBackgroundImage:img];
[tabbar.tabBar setShadowImage:img];
[tabbar.tabBar setBackgroundColor:[UIColor whiteColor]];(如果不加上這行代碼,你的tabbar的顏色是透明的.如果你是自定義的背景視圖,可以在上方的setBackgroundImage添加你自定義的圖片)