UINavigationBar Text Color in Swift
Use NSForegroundColorAttributeName
as key, not "NSForegroundColorAttributeName"
string.
let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]self.navigationController.navigationBar.titleTextAttributes = titleDict
You can also change all UINavigationController
appearances in your app within the AppDelegate.swift
file. Just put the following code within the application:didFinishLaunchingWithOptions
function:
var navigationBarAppearace = UINavigationBar.appearance()navigationBarAppearace.tintColor = UIColor.YourNavigationButtonsColor() // Back buttons and suchnavigationBarAppearace.barTintColor = UIColor.YourBackgroundColor() // Bar's background colornavigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.YourTitleColor()] // Title's text color
Creds: Coderwall's Blog Post
Swift 3+
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
Swift 4.0
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white]