Search code examples
iosobjective-ccocoa-touchuitabbar

Is it possible to set individual tint colors for each button on UITabBar?


Is it possible to have an individual tint color for a single UITabBarItem on the tab bar? I only know how to set it universally with [UITabBar appearance] setTintColor:. But, for example, I want one tab to be tinted with blue when selected, the other one with red etc.

I know it can be partially mitigated by setting image and selectedImage properties with UIImageRenderingModeAlwaysOriginal to preserve the original image colors, but the caption text still has the original tint of the entire tab bar.


Solution

  • Changing the tintColor property individual is impossible, but you can still change the text color for the tab bar item.

    For example:

        [theTabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]}
                                       forState:UIControlStateNormal];
        [theTabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor greenColor]}
                                       forState:UIControlStateHighlighted];