I'm trying to change the tint Color of the back button in iOS 7. Now Is there a way to change all navigation items throughout the entire app to a specific color? This is what i have in one view controller as of right now:
self.editButtonItem.tintColor = [UIColor whiteColor];
self.navigationItem.backBarButtonItem.tintColor = [UIColor whiteColor];
self.navigationController.navigationBarHidden = NO;
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
self.navigationController.navigationBar.translucent = NO;
self.title = @"Inbox";
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
Use any of the . bg-color classes to add a background color to the navbar. Tip: Add a white text color to all links in the navbar with the . navbar-dark class, or use the .
Let's see how to change the background color of a navigation bar through the storyboard editor. Create a new project, select it's view controller and embed in navigation controller. Select the navigation bar and go to It's attribute inspector.
The tint color to apply to the navigation bar background.
Swift answer
UINavigationBar.appearance().backgroundColor = UIColor.blackColor()
UINavigationBar.appearance().barTintColor = UIColor.blackColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
UINavigationBar.appearance().tintColor = UIColor.blackColor()
UIBarButtonItem.appearance().tintColor = UIColor.blackColor()
UITabBar.appearance().backgroundColor = UIColor.blackColor()
UITabBar.appearance().tintColor = UIColor.blackColor()
UITabBar.appearance().unselectedItemTintColor = UIColor.darkGrayColor()
put it in your AppDelegate's func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UINavigationItem
is not a view and it doesn't have a color.
You instead want to change the UIBarButtonItem
tint color.
Using the UIAppearance
proxy you can do
[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
This will change the tintColor
of each UIBarButtonItem
in the application.
You can use the same strategy to change the UINavigationBar
barTintColor
and titleTextAttributes
:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; // this will change the back button tint
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
Unfortunately there's no way of changing the translucent
property using the proxy, so you will have to do it on each bar.
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