iOS-修改系统Tabbar背景色
2016-06-12 本文已影响2489人
一位不愿透露姓名的王先生_
1. 系统默认情况(见下图):
tabBar系统默认颜色.png
2. 自定义 tabBar 背景色效果(见下图):
自定义tabBar背景色.png
3. 代码如下:
// 设置一个自定义 View,大小等于 tabBar 的大小
UIView *bgView = [[UIView alloc] initWithFrame:self.tabBar.bounds];
// 给自定义 View 设置颜色
bgView.backgroundColor = [UIColor redColor];
// 将自定义 View 添加到 tabBar 上
[self.tabBar insertSubview:bgView atIndex:0];
注意:
- 以上代码要写在
appdelegate.m的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法里面
- 或者写在继承自
UITabBarController的自定义的XXTabBarController里面的- (void)viewDidLoad方法里面