How to change Navigation Bar color in iOS 7?

2019-01-01 06:40发布

How do I change the Navigation Bar color in iOS 7?

Basically I want to achieve something like the Twitter Nav Bar (updated Twitter for iOS7 that is). I embedded-in a nav bar atop a view controller. All I want is to change the nav bar color to light blue along with the utility bar at the top. I can't seem to find an option in my storyboard.

18条回答
美炸的是我
2楼-- · 2019-01-01 06:59

It's actually easier than the answers I've seen here:

1) Just make sure you select the navigation bar on the Navigation control. 
2) Select the color you want in the bar tint.
3) You have other options too, and/or individually on each view (just play with it).

I hope this helps somebody. I didn't like the answers I saw. I like to keep my code as clean as possible. Not saying that it's wrong to do it programmatically, but there are people out there like me....this is for you guys. Changing color of the navigation bar

查看更多
十年一品温如言
3楼-- · 2019-01-01 07:02

If you need to support ios6 and ios7 then you get that particular light blue using this in your UIViewController:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *ver = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
    if ([[ver objectAtIndex:0] intValue] >= 7) {
        self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:89/255.0f green:174/255.0f blue:235/255.0f alpha:1.0f];
        self.navigationController.navigationBar.translucent = NO;
    }else{
        self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:89/255.0f green:174/255.0f blue:235/255.0f alpha:1.0f];
    }
}
查看更多
像晚风撩人
4楼-- · 2019-01-01 07:04

Add only This code in your ViewContorller or in your AppDelegate

if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{
    //This is For iOS6
    [self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
}
else
{
    //This is For iOS7
    [self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
}
查看更多
无色无味的生活
5楼-- · 2019-01-01 07:04

This question and these answers are helpful. With them I was able to set my desired dark blue navigationBar color with white title and button text.

But I also needed to change the clock, carrier, signal strength, etc. to white. Black just didn't contrast enough with the dark blue.

I may have overlooked that solution in one of the previous answers, but I was able to make that change by adding this line to my top level viewController's viewDidLoad:

[self.navigationController.navigationBar setBarStyle:UIStatusBarStyleLightContent];
查看更多
皆成旧梦
6楼-- · 2019-01-01 07:09
self.navigationBar.barTintColor = [UIColor blueColor];
self.navigationBar.tintColor = [UIColor whiteColor];
self.navigationBar.translucent = NO;

// *barTintColor* sets the background color
// *tintColor* sets the buttons color
查看更多
何处买醉
7楼-- · 2019-01-01 07:09

For Color :

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

For Image

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationBar_320X44.png"] forBarMetrics:UIBarMetricsDefault];
查看更多
登录 后发表回答