Fullmetal_Alchemist_Fan Fullmetal_Alchemist_Fan - 5 months ago 24
iOS Question

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]};

Answer

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.

Comments