I want to change the tintColor property according to tabbar's selected index. The code I'm using now is not working, all the tabbar views have this code:
- (void)viewDidAppear:(BOOL)animated{
switch (self.tabBarController.selectedIndex) {
case 0:
self.tabBarController.tintColor = [UIColor colorWithRed:147/255 green:22/255 blue:0/255 alpha:1.0];
break;
case 1:
self.tabBarController.tintColor = [UIColor whiteColor];
break;
case 2:
self.tabBarController.tintColor = [UIColor greenColor];
break;
default:
break;
}
}
You don't need to do that; instead, put this in the viewWillAppear:
method of your contained controllers:
Controller 1:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.tabBarController.tabBar.tintColor = [UIColor blueColor];
}
Controller 2:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.tabBarController.tabBar.tintColor = [UIColor yellowColor];
}
This assumes iOS5+. Hope this helps.
Instead of
self.tabBarController.tintColor
Use:
self.tabBarController.tabBar.tintColor
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.