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.

Share:
31,537

Related videos on Youtube

Rani
Author by

Rani

Updated on July 09, 2022

Comments

  • Rani
    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
    Rani about 13 years
    Thanks this is working but can i know what will be the RGB value for dark Green color
  • Rani
    Rani about 13 years
    i have got the color but i now want to make my bar little opaque .How is it possible.Thanks
  • Nick T
    Nick T about 11 years
    Second line of code should read [bar setTintColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0]];
  • PaperThick
    PaperThick over 10 years
    Sorre should't you devide by 255 instead of 256?
  • Desert Rose
    Desert Rose over 10 years
    @PaperThick Thanks for bringing this into notice.
  • sudo
    sudo about 10 years
    It isn't working for me. Could it be that loading my view somehow overrides it?
  • Desert Rose
    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
    sudo about 10 years
    My mistake, I thought this was about the status bar. Different from a navigation bar.
  • Ganpat
    Ganpat over 5 years
    Onwards iOS7 setTintColor not works. Use setBarTintColor instead.

Related