0

I have set color for tab bar in app delegate:

[[UITabBar appearance] setTintColor:[UIColor redColor]];

It works perfect, but I also need to set text color separately. I want my image to be tint with red color, but the text has to be white color.

Is this possible to make?

Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277

2 Answers2

5

to change the color of uitabbaritem used setTitleTextAttributes I hope this code help you :

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [[uicolor whitecolor] }
       forState:UIControlStateSelected];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }
     forState:UIControlStateNormal];

to change the image tintcolor :

[[UITabBar appearance] setTintColor:[UIColor redcolor]];
Aamir
  • 16,329
  • 10
  • 59
  • 65
said
  • 553
  • 5
  • 12
1

The answer at: https://stackoverflow.com/a/18734795/860343 covers most of the edits you may need to do for the tab bar items.

In short here is the code:

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
                                                NSForegroundColorAttributeName : appTintColor
                                                } forState:UIControlStateSelected];


// doing this results in an easier to read unselected state then the default iOS 7 one

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
                                                    NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
                                                    } forState:UIControlStateNormal];
Community
  • 1
  • 1
XIII
  • 2,036
  • 16
  • 25