How to add custom color to navigation bar in iphone?
31,537
Solution 1
Using RGB values like this:
UINavigationBar *bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0]];
Solution 2
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:107.0/255.0 green:145.0/255.0 blue:35.0/255.0 alpha:1.0]];
Place this code in Appdelegate's didfinislaunching
method.It will change the color of the navigation bar for the whole app.
Solution 3
And to change the tint of the navigation bar background :
[self.navBar setBarTintColor:[UIColor colorWithRed:0.701 green:0.926 blue:0.000 alpha:1.000]];
Solution 4
For swift, to change the tint of the navigation bar background :
navigationController?.navigationBar.barTintColor = UIColor.red
Solution 5
[bar setTintColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]]
There are many other ways of getting your color from different kinds of components as described in the documentation.
Related videos on Youtube
Author by
Rani
Updated on July 09, 2022Comments
-
Rani almost 2 years
How do I set the navigation bar to a custom color (e.g. dark green) ?
I know how to change the navigation bar to primary colors like green and red, using code like this:
UINavigationBar *bar = [self.navigationController navigationBar]; [bar setTintColor:[UIColor redColor]];
Thanks.
-
Rani about 13 yearsThanks this is working but can i know what will be the RGB value for dark Green color
-
Rani about 13 yearsi have got the color but i now want to make my bar little opaque .How is it possible.Thanks
-
Nick T about 11 yearsSecond line of code should read [bar setTintColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0]];
-
PaperThick over 10 yearsSorre should't you devide by 255 instead of 256?
-
Desert Rose over 10 years@PaperThick Thanks for bringing this into notice.
-
sudo about 10 yearsIt isn't working for me. Could it be that loading my view somehow overrides it?
-
Desert Rose about 10 years@9000 may be in viewDidLoad or viewWillAppear or viewDidAppear is overwriting this.You can cross check in your view controller.
-
sudo about 10 yearsMy mistake, I thought this was about the status bar. Different from a navigation bar.
-
Ganpat over 5 yearsOnwards iOS7
setTintColor
not works. UsesetBarTintColor
instead.