更改uitabbar默认颜色色调

时间:2015-03-12 14:02:27

标签: objective-c xcode uiviewcontroller uitabbarcontroller uitabbar

我想在未选中时更改uitabbar上的默认灰色调。我的问题是我尝试了下面的代码,但它只显示默认的灰色,然后它变为mu所需的白色色调,这实际上是我的图像颜色。

在didFinishLaunchingWithOptions

[[tabBarController.tabBar.items objectAtIndex:0] setFinishedSelectedImage:nil withFinishedUnselectedImage:[UIImage imageNamed:@"mylib"]];
[[tabBarController.tabBar.items objectAtIndex:1] setFinishedSelectedImage:nil withFinishedUnselectedImage:[UIImage imageNamed:@"explore"]];
[[tabBarController.tabBar.items objectAtIndex:2] setFinishedSelectedImage:nil withFinishedUnselectedImage:[UIImage imageNamed:@"radio"]];
[[tabBarController.tabBar.items objectAtIndex:3] setFinishedSelectedImage:nil withFinishedUnselectedImage:[UIImage imageNamed:@"search"]];
[[tabBarController.tabBar.items objectAtIndex:4] setFinishedSelectedImage:nil withFinishedUnselectedImage:[UIImage imageNamed:@"people"]];

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor colorWithRed:(191/255.0) green:(2/255.0) blue:(6/255.0) alpha:1] }forState:UIControlStateSelected];
    [[UITabBar appearance] setTintColor:[UIColor colorWithRed:(191/255.0) green:(2/255.0) blue:(6/255.0) alpha:1]];

enter image description here

请帮助我想摆脱这个默认的灰色,并希望它是白色的。

1 个答案:

答案 0 :(得分:0)

您可以继承UITabBar,它的viewDidLoad方法可以这样做:

- (void)viewDidLoad {
   [super viewDidLoad];
   //Do your logic here...
}