The UINavigationBar and UISearchBar both have a tintColor property that allows you to change the tint color (surprising, I know) of both of those items. I want to do the same thing to the UITabBar in my application, but have found now way to change it from the default black color. Any ideas?
To change the background color and default tab item colors, some extra work is required as demonstrated below. As shown in lines 2-4, we can use UITabBar. appearance(). backgroundColor to modify the color of the tab bar.
iOS 5 has added some new appearance methods for customising the look of most UI elements.
You can target every instance of a UITabBar in your app by using the appearance proxy.
For iOS 5 + 6:
[[UITabBar appearance] setTintColor:[UIColor redColor]];
For iOS 7 and above, please use the following:
[[UITabBar appearance] setBarTintColor:[UIColor redColor]];
Using the appearance proxy will change any tab bar instance throughout the app. For a specific instance, use one of the new properties on that class:
UIColor *tintColor; // iOS 5+6 UIColor *barTintColor; // iOS 7+ UIColor *selectedImageTintColor; UIImage *backgroundImage; UIImage *selectionIndicatorImage;
I have been able to make it work by subclassing a UITabBarController and using private classes:
@interface UITabBarController (private) - (UITabBar *)tabBar; @end @implementation CustomUITabBarController - (void)viewDidLoad { [super viewDidLoad]; CGRect frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 48); UIView *v = [[UIView alloc] initWithFrame:frame]; [v setBackgroundColor:kMainColor]; [v setAlpha:0.5]; [[self tabBar] addSubview:v]; [v release]; } @end
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