How to change navigation bar color in iOS 7 or 6?

IosIos6Interface BuilderIos7

Ios Problem Overview


I want to change the color of the navigation bar color, but I'm not sure whether or not I should change the tint or the background. I know iOS 7 is going for a more flat design (even recommending removing gradients), but I am having trouble deciphering the two. Even if I set a background color, it doesn't do anything.

In this image, the background is set to green, but the bar is still blue:

Enter image description here

Ios Solutions


Solution 1 - Ios

The behavior of tintColor for bars has changed on iOS 7.0. It no longer affects the bar's background and behaves as described for the tintColor property added to UIView. To tint the bar's background, please use -barTintColor.

navController.navigationBar.barTintColor = [UIColor navigationColor];

Solution 2 - Ios

If you want to have a solid color for your navigation bar in iOS 6 similar to iOS 7 use this:

[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor greenColor]];

in iOS 7 use the barTintColor like this:

navigationController.navigationBar.barTintColor = [UIColor greenColor];

or

 [[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];

Solution 3 - Ios

// In ios 7 :-

[self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];

// In ios 6 :-

[self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];

Solution 4 - Ios

The background color property is ignored on a UINavigationBar, so if you want to adjust the look and feel you either have to use the tintColor or call some of the other methods listed under "Customizing the Bar Appearance" of the UINavigationBar class reference (like setBackgroundImage:forBarMetrics:).

Be aware that the tintColor property works differently in iOS 7, so if you want a consistent look between iOS 7 and prior version using a background image might be your best bet. It's also worth mentioning that you can't configure the background image in the Storyboard, you'll have to create an IBOutlet to your UINavigationBar and change it in viewDidLoad or some other appropriate place.

Solution 5 - Ios

One more thing, if you want to change the navigation bg color in UIPopover you need to set barStyle to UIBarStyleBlack

if([UINavigationBar instancesRespondToSelector:@selector(barTintColor)]){ //iOS7
    navigationController.navigationBar.barStyle = UIBarStyleBlack;
    navigationController.navigationBar.barTintColor = [UIColor redColor];
}

Solution 6 - Ios

Here is how to set it correctly for both iOS 6 and 7.

+ (void)fixNavBarColor:(UINavigationBar*)bar {
    if (iosVersion >= 7) {
        bar.barTintColor = [UIColor redColor];
        bar.translucent = NO;
    }else {
        bar.tintColor = [UIColor redColor];
        bar.opaque = YES;
    }
}

Solution 7 - Ios

The complete code with version checking.

 if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
    
    // do stuff for iOS 7 and newer
    [self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
}
else {
    
    // do stuff for older versions than iOS 7
    [self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
}

Solution 8 - Ios

You can check iOS Version and simply set the tint color of Navigation bar.

if (SYSTEM_VERSION_LESS_THAN(@"7.0")) {
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.9529 green:0.4392 blue:0.3333 alpha:1.0];
}else{
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.9529 green:0.4392 blue:0.3333 alpha:1.0];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

Solution 9 - Ios

Based on posted answered, this worked for me:

/* check for iOS 6 or 7 */
if ([[self navigationController].navigationBar respondsToSelector:@selector(setBarTintColor:)]) {
    [[self navigationController].navigationBar setBarTintColor:[UIColor whiteColor]];

} else {
    /* Set background and foreground */
    [[self navigationController].navigationBar setTintColor:[UIColor whiteColor]];
    [self navigationController].navigationBar.titleTextAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:[UIColor blackColor],UITextAttributeTextColor,nil];
}

Solution 10 - Ios

    you can add bellow code in appdelegate.m .if your app is navigation based

    // for background color
   [nav.navigationBar setBarTintColor:[UIColor blueColor]];

    // for change navigation title and button color
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],
    NSForegroundColorAttributeName,               
    [UIFont fontWithName:@"FontNAme" size:20],
    NSFontAttributeName, nil]];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

Solution 11 - Ios

Insert the below code in didFinishLaunchingWithOptions() in AppDelegate.m

[[UINavigationBar appearance] setBarTintColor:[UIColor
    colorWithRed:26.0/255.0 green:184.0/255.0 blue:110.0/255.0 alpha:1.0]];

Solution 12 - Ios

I'm using following code (in C#) to change the color of the NavigationBar:

NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.Default);
NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.LandscapePhone);
NavigationController.NavigationBar.BackgroundColor = UIColor.Green;

The trick is that you need to get rid of the default background image and then the color will appear.

Solution 13 - Ios

If you want to change a color of a navigation bar, use barTintColor property of it. In addition, if you set any color to tintColor of it, that affects to the navigation bar's item like a button.

FYI, you want to keep iOS 6 style bar, make a background image looks like previous style and set it.

For more detail, you can get more information from the following link:

https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

Solution 14 - Ios

In iOS7, if your navigation controller is contained in tab bar, splitview or some other container, then for globally changing navigationbar appearance use following method ::

[[UINavigationBar appearanceWhenContainedIn:[UITabBarController class],nil] setBarTintColor:[UIColor blueColor]];

Solution 15 - Ios

Try the code below in the - (void)viewDidLoad of your ViewController.m

[[[self navigationController] navigationBar] setTintColor:[UIColor yellowColor]];

this did work for me in iOS 6.. Try it..

Solution 16 - Ios

I'm not sure about changing the tint vs the background color but this is how you change the tint color of the Navigation Bar:

Try this code..

[navigationController.navigationBar setTintColor:[UIColor redColor]; //Red as an example.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEGHDKView Question on Stackoverflow
Solution 1 - IosMaheshView Answer on Stackoverflow
Solution 2 - IosCarmenView Answer on Stackoverflow
Solution 3 - IosAshishView Answer on Stackoverflow
Solution 4 - IosCharles A.View Answer on Stackoverflow
Solution 5 - IosTarek HallakView Answer on Stackoverflow
Solution 6 - IospizzamonsterView Answer on Stackoverflow
Solution 7 - Ioskalan nawarathneView Answer on Stackoverflow
Solution 8 - IosPRITAM SATPUTEView Answer on Stackoverflow
Solution 9 - IosRoozbeh ZabihollahiView Answer on Stackoverflow
Solution 10 - IosHitesh VaghelaView Answer on Stackoverflow
Solution 11 - IosARSHWIN DENUEV LALView Answer on Stackoverflow
Solution 12 - IostomecView Answer on Stackoverflow
Solution 13 - IosKyokook HwangView Answer on Stackoverflow
Solution 14 - IosmuzzView Answer on Stackoverflow
Solution 15 - Iosgeet SebastianView Answer on Stackoverflow
Solution 16 - IosKevin CronlyView Answer on Stackoverflow