改变UITabBar的背景色

默认的UITabBar的背景色是黑色的,我们有的时候需要设置一些自定的颜色,来达到自定义的要求,下面就来说说在iOS6和iOS7中如果进行设置的,下面设置背景色为白色:

iOS6

1
2
3
4
5
6
7
8
9
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.tabBar.backgroundImage = image;

iOS7

1
2
3
4
UIView *bgView = [[UIView alloc] initWithFrame:self.tabBar.bounds];
bgView.backgroundColor = [UIColor whiteColor];
[self.tabBar insertSubview:bgView atIndex:0];
self.tabBar.opaque = YES;
文章目录
  1. 1. iOS6
  2. 2. iOS7
,