Reputation: 358
Somebody writes this kind of code
override func viewDidLoad() {
super.viewDidLoad()
// Status bar white font
self.navigationBar.barStyle = UIBarStyle.Black
self.navigationBar.tintColor = UIColor.whiteColor()
}
but it doesn't work, updating it in AppDelegate really works, but why it doesn't work from viewDidLoad?
Upvotes: 0
Views: 819
Reputation: 761
You can set these properties in XIB/Storyboard. No need to set it in every controller.
If you want to set it from view controller so you need to self.navigationController?.navigationBar.barTintColor = typeyourcolor.
Navigation bar is the property of navigation controller not the view controller.
Upvotes: 1
Reputation: 2547
try this :
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.barStyle = .black
self.navigationController?.navigationBar.tintColor = UIColor.white
}
Upvotes: 1
Reputation: 417
If you want to change navigation bar background colour then use below code
self.navigationController?.navigationBar.barTintColor = UIColor.green
and If you want to change navigation bar Item colour then use below code
self.navigationController?.navigationBar.tintColor = UIColor.red
Upvotes: 1
Reputation: 47099
If you want to change navigation bar background colour then use below code
self.navigationController?.navigationBar.barTintColor = UIColor.red // set what ever color that you wanr.
Upvotes: 1