Search code examples
iosswiftxcodeios8uinavigationbar

NavigationBar bar, tint, and title text color in iOS 8


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.viewDidLoad()
    self.navigationController?.navigationBar.barTintColor = UIColor.blackColor()
    self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orangeColor()]

}

enter image description here


Solution

  • 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