I need to change the selection color of UITabBar from default blue to red. How do we do this.
iOS 5.0 fixes this issue but the solution is under NDA. Look up UITabBar in your documentation for an EASY way to do what you want to do.
Because UITextAttributeTextColor is deprecated in iOS 7, you should use:
[UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor greenColor]} forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor purpleColor]} forState:UIControlStateSelected];
The SDK does not make this easy, but it is technically possible. Apple apparently believes this to be part of their vision of a consistent look and feel.
UITabBar is a subclass of UIView. You can always subclass and implement your own -drawRect:
This is not a trivial task, however, you have to essentially re-implement the class from scratch or you risk some weird side-effects.
It is extremely easy
Create a custom class of UITabBarController and in -(void)viewDidLoad
method add this line:
[[self tabBar] setSelectedImageTintColor:[UIColor greenColor]];
In iOS 7 it's simply the tintColor. One way to accomplish this could be to subclass UITabBarViewController, set the custom class in the storyboard, and in your viewDidLoad
method of the subclassed tabBarVC add this:
[[self tabBar] setTintColor:[UIColor redColor]];
Starting from iOS 8 it's as simple as:
UITabBar.appearance().tintColor = UIColor.redColor()