10

I want to change UINavigationBar color globally for the whole application from the AppDelegate. For it I do:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
UINavigationBar.appearance().tintColor = UIColor(red: 63, green: 172, blue: 236, alpha: 1)
}

but, I do not know why, it doesn't change the color of my Navigation bar.

I had connect Navigation Bar as Editor > Embed In > Navigation Controller

How can I set the color for NavBar?

Orkhan Alizade
  • 7,379
  • 14
  • 40
  • 79
  • 1
    possible duplicate of [How to change UINavigationBar background color from the app delegate](http://stackoverflow.com/questions/17014713/how-to-change-uinavigationbar-background-color-from-the-app-delegate) – Hyder Jun 16 '15 at 05:14
  • 1
    You just forgot to divide with 255 and use the barTintColor to set color for navigation bar. I have added a answer. Hope it helps – Ashish Kakkad Jun 16 '15 at 05:22

3 Answers3

30

set barTintColor

UINavigationBar.appearance().barTintColor = UIColor(red: 63.0/255.0, green: 172.0/255.0, blue: 236.0/255.0, alpha: 1.0)

I think you forgot to divide with 255

For turn off the translucent. In your first root controller do it as follows.

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController!.navigationBar.translucent = false
}

Swift 3 :

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController!.navigationBar.isTranslucent = false
}

My output:

enter image description here

Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
1

Use this

navigationController.navigationBar.barTintColor = UIColor.greenColor()
Kishore Suthar
  • 2,943
  • 4
  • 26
  • 44
0

You can use this

Objective C:

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

Swift:

self.navigationController.navigationBar.barTintColor = UIColor.yellowColor()

It will make you navigation bar with yellow color.

PS : Don't use tintColor, tint color is for back buttons titles.

A navigation bar has other properties as well. You can check them on Apple site as well & can apply solutions as per your need.

https://developer.apple.com/reference/uikit/uinavigationbar

Ash
  • 5,525
  • 1
  • 40
  • 34