Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar background color - translucency is no

I would like to change the background color of the navigation bar to a solid green.

Rule: I can't mess with the AppDelegate :)

I've tried:

//It's green but it's translucent 
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];

//It's white, first line has no effect
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];
[self.navigationController.navigationBar setTranslucent:NO];

//Same result as case 1
[self.navigationController.navigationBar setAlpha:0.0f];
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];

//Too dark
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];

//Only affects the back button's color:
[self.navigationController.navigationBar setTintColor:[UIColor greenColor]];

So any ideas?

Thank you, didn't see there was barTintColor and TintColor as well. Accepting earliest answer.

like image 349
Lord Zsolt Avatar asked Sep 30 '13 12:09

Lord Zsolt


People also ask

How do I make my navigation bar translucent?

Creating a transparent navbar is very easy - just don't add a color class . bg-* to the navbar. In this case, the Navbar will take the color of the parent's background color.

What color should the navigation bar be?

By default, your top navigation bar's background color will be white. For aesthetic preferences or to better contrast your logo's colors, you may want to change this.

How do I change my navigation bar background?

In order to change the hub navigation bar color, we can go to site settings of hub site>Change the look>under the header section>Background> select a theme color to change the background color of your site header.


1 Answers

Use this line of code in your viewController didLoad method

self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:29.0f/255.0f green:149.0f/255.0f blue:174.0f/255.0f alpha:1.0f] 
like image 176
Priyatham51 Avatar answered Sep 30 '22 19:09

Priyatham51