How can I change the color of \"More..\" text in tabbar to match with its icon
Swift version of @skywinder answer :
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.whiteColor()], forState: .Normal)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.whiteColor()], forState: .Selected)
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.
Swift 4:
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor : UIColor.white], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor : UIColor.red], for: .selected)
This worked for me on Swift 5.
In AppDelegate :
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.red], for: .selected)
For a swift solution, let type inference be your friend:
override func viewWillAppear(animated: Bool) {
for item in self.tabBar.items! {
let unselectedItem = [NSForegroundColorAttributeName: UIColor.blackColor()]
let selectedItem = [NSForegroundColorAttributeName: UIColor.whiteColor()]
item.setTitleTextAttributes(unselectedItem, forState: .Normal)
item.setTitleTextAttributes(selectedItem, forState: .Selected)
}
}
This works correctly..
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor], NSForegroundColorAttributeName,
nil] forState:UIControlStateSelected];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor], NSForegroundColorAttributeName,
nil] forState:UIControlStateNormal];