NavigationBar bar, tint, and title text color in iOS 8
Solution 1:
In AppDelegate.swift
, in application(_:didFinishLaunchingWithOptions:)
I put the following:
UINavigationBar.appearance().barTintColor = UIColor(red: 234.0/255.0, green: 46.0/255.0, blue: 73.0/255.0, alpha: 1.0)
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
(For Swift 4 or earlier use NSAttributedStringKey
instead of NSAttributedString.Key
)
For titleTextAttributes
, the docs say:
You can specify the font, text color, text shadow color, and text shadow offset for the title in the text attributes dictionary
Solution 2:
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
}