I have an application which uses a tab bar. I want each tab to use a different tint color. Is there a way to have each tabBarItem be selected with a different color? Thanks!
Asked
Active
Viewed 350 times
1 Answers
3
If you are using a UITabBarController, you can simply implement the following delegate and change the color for each tabs as you want.
In case you aren't using the UITabBarController, just add the correct delegate to your UITabBar.
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSUInteger indexOfTab = [[tabBar items] indexOfObject:item];
UIColor *colorToApply;
switch (indexOfTab) {
case 0:
colorToApply = [UIColor colorWithRed: 255.0/255.0 green: 64.0/255.0 blue: 98.0/255.0 alpha: 1.0];
break;
case 1:
colorToApply = [UIColor colorWithRed: 254.0/255.0 green: 156.0/255.0 blue: 152.0/255.0 alpha: 1.0];
break;
case 2:
colorToApply = [UIColor colorWithRed: 250.0/255.0 green: 205.0/255.0 blue: 171.0/255.0 alpha: 1.0];
break;
case 3:
colorToApply = [UIColor colorWithRed: 200.0/255.0 green: 200.0/255.0 blue: 168.0/255.0 alpha: 1.0];
break;
case 4:
colorToApply = [UIColor colorWithRed: 130.0/255.0 green: 175.0/255.0 blue: 155.0/255.0 alpha: 1.0];
break;
default:
break;
}
tabBar.tintColor = colorToApply;
}

Lukas
- 1,346
- 7
- 24
- 49
-
1It was hard to find this post, but finally it helped me so much. Thx ! – QLag Feb 22 '14 at 12:49
-
@lucè-brùlè what would be the delegate for UITabBar? – user1324887 Jul 28 '16 at 07:41