Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 926
Orkhan Alizade Avatar asked Jun 16 '15 05:06

Orkhan Alizade


2 Answers

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

like image 167
Ashish Kakkad Avatar answered Nov 14 '22 12:11

Ashish Kakkad


Use this

navigationController.navigationBar.barTintColor = UIColor.greenColor()
like image 25
Kishore Suthar Avatar answered Nov 14 '22 11:11

Kishore Suthar