0

Can someone tell me how I can set the colour of a navigation bar in a view controller?

I used this:

UINavigationBar *navigationBar = self.navigationController.navigationBar;

[navigationBar setBackgroundColor:[UIColor redColor]];

self.navigationController.navigationBar.tintColor = [UIColor redColor];

Can someone can tell me what is tintColor and how it differs from the backgroundColor?

2
  • The documentation has all this information:developer.apple.com/library/ios/documentation/uikit/reference/… . Look at the barTintColor property in order to change the navigation bar background colour. Commented Feb 12, 2014 at 22:59
  • "Can someone can tell me what is tintColor and how it differs from the backgroundColor" Actually for iOS 7 it is the difference between backgroundColor and barTintColor that you should worry about; tintColor is unrelated. Commented Feb 12, 2014 at 23:38

2 Answers 2

1

Change the background color of the navigation bar is easy. For example, next code changes it to blue :

[ self.navigationController.navigationBar setBarTintColor :
                     [ UIColor colorWithRed : ( 0x0  / 255 )
                                      green : ( 0x0  / 255 )
                                       blue : ( 0xff / 255 )
                                              alpha : 1 ] ];

You can add the previous code to your viewDidLoad method.

Sign up to request clarification or add additional context in comments.

Comments

0

To change the nav bar color use:

//Custom Navbar using image
UIImage *navbar = [UIImage imageNamed:@"navbar.png"];
[[UINavigationBar appearance] setBackgroundImage:navbar forBarMetrics:UIBarMetricsDefault];

//Navbar color
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

//Change the text color
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIColor whiteColor],     NSForegroundColorAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];

Taken from: http://ios-blog.co.uk/tutorials/ios-custom-ui-series-tabbar-navbar/ by Rob Whitlow

1 Comment

The OP doesn't ask about UITabBar. The question explicitly states that the OP is interested in setting the colour of the navigation bar.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.