Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change tab bar item text color

enter image description here

How can I change the color of "More.." text in tabbar to match with its icon color. (Right now Performance is selected in the tab bar)

I tried to set TitleTextAttributes.

[moreItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"HelveticaLTStd-Roman" size:10.0f], NSFontAttributeName,  [UIColor yellowColor],NSForegroundColorAttributeName , nil]

But it the text color is always set to yellow. even when the item is selected. Like this enter image description here

I am trying set to white when selected and when unselected it should match with icon color. Thanks.. Any suggestions will be really helpful.

like image 933
Priyatham51 Avatar asked Sep 08 '13 20:09

Priyatham51


People also ask

How do I change font color on tab bar?

How to change tab bar text color (selected/unselected) In tab bar, there are two states of the text. One is when tab is selected and another one is when the tab is unselected. To change the text color for selected state, inside the TabBar widget, add the labelColor property and set the color.

How do I change the color of my tab bar in Swift?

Add Runtime Color attribute named "tintColor". It will change image tint color as well as title tint color.


3 Answers

The accepted answer's code not work for me.

Here is code, that works:

    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor yellowColor] }
                                             forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }
                                             forState:UIControlStateSelected];
like image 158
skywinder Avatar answered Sep 29 '22 00:09

skywinder


I found the answer for my own question.

We can set perforamceItem setTitleTextAttributes: for two different states.

  • forState:UIControlStateNormal
  • forState:UIControlStateHighlighted

I added the following code

 [performanceItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"HelveticaLTStd-Roman" size:10.0f], NSFontAttributeName,  [UIColor yellowColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];

[performanceItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"HelveticaLTStd-Roman" size:10.0f], NSFontAttributeName,  [UIColor whiteColor], NSForegroundColorAttributeName,nil] forState:UIControlStateHighlighted];

I need to replace the yellow color with the color of my ICONS. This is how they are looking now.

When More is selected

When More is selected

When Performance is Selected

When Performance is Selected

like image 37
Priyatham51 Avatar answered Sep 28 '22 23:09

Priyatham51


Code free way to do this:

If you are just using iOS 10 then you may change the Image Tint in your Tab Bar

enter image description here

If you are also supporting iOS 9 and lower, then you must also add tintColor to your user definer runtime attributes in each tab bar item

enter image description here

if you also wish to change your icon color make sure the correct color image is in your assest folder and change Render as to Original Image

enter image description here

like image 33
HannahCarney Avatar answered Sep 29 '22 00:09

HannahCarney