How to change Navigation Bar color in iOS 7? How to change Navigation Bar color in iOS 7? ios ios

How to change Navigation Bar color in iOS 7?


The behavior of tintColor for bars has changed in iOS 7.0. It no longer affects the bar's background.

From the documentation:

barTintColor Class Reference

The tint color to apply to the navigation bar background.

@property(nonatomic, retain) UIColor *barTintColor

Discussion
This color is made translucent by default unless you set the translucent property to NO.

Availability

Available in iOS 7.0 and later.

Declared In
UINavigationBar.h

Code

NSArray *ver = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];if ([[ver objectAtIndex:0] intValue] >= 7) {    // iOS 7.0 or later       self.navigationController.navigationBar.barTintColor = [UIColor redColor];    self.navigationController.navigationBar.translucent = NO;}else {    // iOS 6.1 or earlier    self.navigationController.navigationBar.tintColor = [UIColor redColor];}

We can also use this to check iOS Version as mention in iOS 7 UI Transition Guide

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {        // iOS 6.1 or earlier        self.navigationController.navigationBar.tintColor = [UIColor redColor];    } else {        // iOS 7.0 or later             self.navigationController.navigationBar.barTintColor = [UIColor redColor];        self.navigationController.navigationBar.translucent = NO;    }

EDITUsing xib

enter image description here


Doing what the original question asked—to get the old Twitter's Nav Bar look, blue background with white text—is very easy to do just using the Interface Builder in Xcode.

  • Using the Document Outline, select your Navigation Bar.
  • In the Attributes Inspector, in the Navigation Bar group, change the Style from Default to Black. This changes the background colour of the Navigation and Status bars to black, and their text to white. So the battery and other icons and text in the status bar will look white when the app is running.
  • In the same Navigation Bar group, change the Bar Tint to the colour of your liking.
  • If you have Bar Button items in your Navigation Bar, those will still show their text in the default blue colour, so in the Attributes Inspector, View group, change the Tint to White Colour.

That should get you what you want. Here is a screenshot that would make it easier to see where to make the changes.

Where to make the necessary changes, including the result in iOS Simulator

Note that changing only the Bar Tint doesn't change the text colour in the Navigation Bar or the Status Bar. The Style also needs to be changed.


self.navigationBar.barTintColor = [UIColor blueColor];self.navigationBar.tintColor = [UIColor whiteColor];self.navigationBar.translucent = NO;// *barTintColor* sets the background color// *tintColor* sets the button's color