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:55

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.

查看更多
路过你的时光
3楼-- · 2019-01-01 06:55

In viewDidLoad, set:

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

Change ( blueColor ) to whatever color you'd like.

查看更多
十年一品温如言
4楼-- · 2019-01-01 06:56

In iOS 7 you must use the -barTintColor property:

navController.navigationBar.barTintColor = [UIColor barColor];
查看更多
查无此人
5楼-- · 2019-01-01 06:57
//You could place this code into viewDidLoad
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBar.tintColor = [UIColor redColor];
    //change the nav bar colour
    self.navigationController.view.backgroundColor = [UIColor redColor];
    //change the background colour
    self.navigationController.navigationBar.translucent = NO;
 }   
//Or you can place it into viewDidAppear
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:(BOOL)animated];
    self.navigationController.navigationBar.tintColor = [UIColor redColor];
    //change the nav bar colour
    self.navigationController.view.backgroundColor = [UIColor redColor];
    //change the background colour
    self.navigationController.navigationBar.translucent = NO;
}
查看更多
后来的你喜欢了谁
6楼-- · 2019-01-01 06:57
- (void)viewDidLoad
{
    [super viewDidLoad];

    self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
}
查看更多
与君花间醉酒
7楼-- · 2019-01-01 06:59

In a Navigation based app you can put the code in AppDelegate. A more detailed code could be:

// Navigation bar appearance (background and title)

[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor titleColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"FontNAme" size:titleSize], NSFontAttributeName, nil]];

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

// Navigation bar buttons appearance

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor textBarColor], NSForegroundColorAttributeName, shadowColor, NSShadowAttributeName, [UIFont fontWithName:@"FontName" size:titleSize], NSFontAttributeName, nil];
查看更多
登录 后发表回答