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
I am trying set to white when selected and when unselected it should match with icon color. Thanks.. Any suggestions will be really helpful.
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.
Add Runtime Color attribute named "tintColor". It will change image tint color as well as title tint color.
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];
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.
Code free way to do this:
If you are just using iOS 10 then you may change the Image Tint in your Tab Bar
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With