Orkhan Alizade Orkhan Alizade - 1 month ago 21
iOS Question

How to change UINavigationBar color globally?

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?

Answer

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