Reputation: 144
How can I set a tint color to a specific navigation controller ?
Because by using :
UINavigationBar.appearance().barTintColor = UIColor(red: 0.1, green: 0.22, blue: 0.212, alpha: 1)
The color will be set to all navigation controllers , isn't it ?
I've tried this code but it is not working ! Why ?
let nav = UINavigationController(rootViewController: feedvc)
nav.navigationBar.appearance().barTintColor = UIColor(red: 0.1, green: 0.22, blue: 0.212, alpha: 1)
Upvotes: 0
Views: 883
Reputation: 37600
appearance() is used for changing things on a global scale and it takes effect for the next instance of something that is created.
So for example if you set it in the viewDidLoad of an object which is of the same type as you are applying appearance() then it is too late as that object has already been created. However in your case you are calling it on an instance not a class and so it wouldn't work anyway as it is a class method not an object method.
That is why it is not working in your code, to change the color just set nav.navigationBar.barTintColor
.
Upvotes: 1
Reputation: 7085
You can set the tint of a specific controller by accessing barTintColor
directly:
nav.navigationBar.barTintColor = UIColor(red: 0.1, green: 0.22, blue: 0.212, alpha: 1)
Upvotes: 1