Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing navigation items color through the entire app?

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]};
like image 671
Fullmetal_Alchemist_Fan Avatar asked Oct 25 '13 19:10

Fullmetal_Alchemist_Fan


People also ask

How do I change the background color of my navigation bar?

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 .

How do I change the color of the navigation bar in IOS Swift?

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.

What is barTintColor?

The tint color to apply to the navigation bar background.


2 Answers

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 {

like image 82
drpawelo Avatar answered Nov 15 '22 19:11

drpawelo


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.

like image 44
Gabriele Petronella Avatar answered Nov 15 '22 18:11

Gabriele Petronella