16

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]};
  • 1
    I've answer a similar question: http://stackoverflow.com/questions/18929864/how-do-i-change-the-navigation-bar-color-in-ios-7/18934411#18934411 – RFG Oct 25 '13 at 19:14

6 Answers6

32

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.

Community
  • 1
  • 1
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
4

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 {

drpawelo
  • 2,348
  • 23
  • 17
0

Starting from iOS7 you can set a tintcolor for all the navigation items just to keep a consistent look and feel all over the app:

 if ([self.window respondsToSelector:@selector(setTintColor:)]) {
        self.window.tintColor = [UIColor redColor];
}

Also look at my answer here for recommended reading and viewing material: StatusBar bug in iOS7?

Community
  • 1
  • 1
Arsalan Habib
  • 1,395
  • 14
  • 20
  • I think the user is asking about `UINavigationBar` and `UIBarButtonItem`, your answer applies for more than he asks. – Roland Dec 12 '13 at 18:58
0

In the superViewDidLoad method.

self.navigationController.navigationBar.barTintColor = [UIColor redColor];

it would change the color of navigation item's color. And same will happen with button.

DanSkeel
  • 3,853
  • 35
  • 54
0

This works for changing the back button color:

   [[UINavigationBar appearance] setTintColor:[UIColor redColor]];

Tested with iOS 9.3, iPhone and iPad. Your navigationBar title will still be colorized with the default color. It was is a little confusing.

Mexx
  • 359
  • 3
  • 17
0

For Title Label Color, we can use

self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
dbc
  • 104,963
  • 20
  • 228
  • 340