Just to figure it out a bit ...
If you want to change the appearance for all elements of the tab bar, use:
Objective-C:
[[UITabBarItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor :[UIColor someColor]} forState:UIControlStateSelected];
Swift:
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.someColor()], forState: .Selected)
However , if you just want to set the appearance of one element, do this:
Objective-C:
[self.tabBarItem setTitleTextAttributes:@{UITextAttributeTextColor :[UIColor someColor]} forState:UIControlStateSelected];
Swift:
tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.someColor()], forState: .Selected)
Note : tabBarItem is a property on a UIViewController . This means that although every property of the UIViewController has this property, it may not be the tabBarItem you are looking for. This often happens when your view controller is enclosed in a UINavigationController . In this case, refer to tabBarItem on the navigation controller, and not to the root controller (or another).
Ben lachman
source share