Reputation: 6550
Is there a way to change the tint of a tab bar on iOS 7 from the default white with blue icons to another color tint with different color buttons?
Upvotes: 75
Views: 104117
Reputation: 18470
Try the below:
[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];
To tint the non active buttons, put the below code in your VC's viewDidLoad
:
UITabBarItem *tabBarItem = [yourTabBarController.tabBar.items objectAtIndex:0];
UIImage *unselectedImage = [UIImage imageNamed:@"icon-unselected"];
UIImage *selectedImage = [UIImage imageNamed:@"icon-selected"];
[tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem setSelectedImage: selectedImage];
You need to do this for all the tabBarItems, and yes I know it is ugly and hope there will be cleaner way to do this.
Swift:
UITabBar.appearance().tintColor = UIColor.red
tabBarItem.image = UIImage(named: "unselected")?.withRenderingMode(.alwaysOriginal)
tabBarItem.selectedImage = UIImage(named: "selected")?.withRenderingMode(.alwaysOriginal)
Upvotes: 207
Reputation: 9639
What finally worked for me was:
[self.tabBar setTintColor:[UIColor redColor]];
[self.tabBar setBarTintColor:[UIColor yellowColor]];
Upvotes: 2
Reputation: 1
You can set your tint color and font as setTitleTextattribute:
UIFont *font= (kUIScreenHeight>KipadHeight)?[UIFont boldSystemFontOfSize:32.0f]:[UIFont boldSystemFontOfSize:16.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,
tintColorLight, NSForegroundColorAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
Upvotes: -3
Reputation:
In "Attributes Inspector" of your Tab Bar Controller within Interface Builder make sure your Bottom Bar is set to Opaque Tab Bar:
Now goto your AppDelegate.m file. Find:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
And then add this code between the curly braces to change the colors of both the tab bar buttons and the tab bar background:
///----------------SET TAB BAR COLOR------------------------//
//--------------FOR TAB BAR BUTTON COLOR---------------//
[[UITabBar appearance] setTintColor:[UIColor greenColor]];
//-------------FOR TAB BAR BACKGROUND COLOR------------//
[[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
Upvotes: 1
Reputation: 342
After trying out all the suggested solutions, I couldn't find any very helpful.
I finally tried the following:
[self.tabBar setTintColor:[UIColor orangeColor]];
which worked out perfectly.
I only provided one image for every TabBarItem. Didn't even need a selectedImage.
I even used it inside the Child-ViewControllers to set different TintColors:
UIColor *theColorYouWish = ...;
if ([[self.parentViewController class] isSubclassOfClass:[UITabBarController class]]){
UITabBarController *tbc = (UITabBarController *) self.parentViewController;
[tbc.tabBar setTintColor:theColorYouWish];
}
Upvotes: 0
Reputation: 3822
iOS 7.1.1
If someone is going to need to use globally setting tint color:
[[UIView appearance] setTintColor:[UIColor whiteColor]];
In didFinishLaunchingWithOptions
of AppDelegate
.
Also below code will change only tab bar tint color in any viewDidLoad
method:
[self.tabBarController.tabBar setTintColor:[UIColor redColor]];
Upvotes: 18
Reputation: 441
Write this in your View Controller class of your Tab Bar:
// Generate a black tab bar
self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
// Set the selected icons and text tint color
self.tabBarController.tabBar.tintColor = [UIColor orangeColor];
Upvotes: 8
Reputation: 3939
In app delegate didFinishLaunchingWithOptions:
window.tintColor = [UIColor purpleColor];
sets the tint color globally for the app.
Upvotes: 9
Reputation: 239
There is an much easier way to do this.
Just open the file inspector and select a "global tint".
You can also set an app’s tint color in Interface Builder. The Global Tint menu in the Interface Builder Document section of the File inspector lets you open the Colors window or choose a specific color.
Also see:
Upvotes: 22