The background text in the status bar is still black. How do I change the color to white?
// io8, swift, Xcode 6.0.1
override func viewDidLoad() {
super
Setting text color of navigation bar title to white in Swift version 4.2:
navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
Swift 4.1
Add a func to viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
setup()
}
In the setup()
function add:
func setup() {
navigationController?.navigationBar.prefersLargeTitles = true
navigationController?.navigationBar.barStyle = .blackOpaque
navigationItem.title = "YOUR_TITLE_HERE"
navigationController?.navigationBar.barTintColor = .black
let attributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
navigationController?.navigationBar.largeTitleTextAttributes = attributes
}
Updated with swift 4
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.tintColor = UIColor.blue
self.navigationController?.navigationBar.barStyle = UIBarStyle.black
}
In Swift5 and Xcode 10
self.navigationItem.title = "your name"
let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
navigationController?.navigationBar.titleTextAttributes = textAttributes
Swift 4
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBar.barTintColor = UIColor.orange
navigationController?.navigationBar.tintColor = UIColor.white
navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
}
I like Alex's answer. If you want something quick to try out in a ViewController
make sure you use
viewWillAppear()
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
var nav = self.navigationController?.navigationBar
nav?.barStyle = UIBarStyle.Black
nav?.tintColor = UIColor.white
nav?.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orange]
//nav?.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.orange] // swift 4.2
}