Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Tint / Background color of UITabBar

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?

like image 924
pixel Avatar asked Feb 20 '09 20:02

pixel


People also ask

How do I change the Tabview color in Swiftui?

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.


2 Answers

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; 
like image 115
imnk Avatar answered Sep 22 '22 23:09

imnk


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 
like image 36
coneybeare Avatar answered Sep 26 '22 23:09

coneybeare