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
Swift 4.2 version of Albert's answer-
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 = [.foregroundColor : UIColor.white]
For custom color to TitleText
at NavigationBar
, here a simple and short code for Swift 3:
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
or
navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName :UIColor.white]
To change the color universally, this code should sit in the NavigationController
's viewDidLoad
function:
class NavigationController: UINavigationController, UIViewControllerTransitioningDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Status bar white font
self.navigationBar.barStyle = UIBarStyle.Black
self.navigationBar.tintColor = UIColor.whiteColor()
}
}
To change it per ViewController
you would have to reference the NavigationController
from the ViewController
and write similar lines in that ViewController
's viewWillAppear
function.
self.navigationController?.navigationItem.largeTitleDisplayMode = .always
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
// unconfirmed but I assume this works:
self.navigationController?.navigationBar.barTintColor = UIColor.white
self.navigationController?.navigationBar.barStyle = UIBarStyle.black
Swift 5.1
Only copy and Paste in ViewDidLoad()
and Change its and size as your need.
Before copy and paste add Navigation Bar on top of the Screen.
navigationController?.navigationBar.titleTextAttributes = [ NSAttributedString.Key.font: UIFont(name: "TitilliumWeb-Bold.ttf", size: 16.0)!, NSAttributedString.Key.foregroundColor: UIColor.white]
If it not work then you can try for only change its text color
navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
To work in objective-c I have to put the following lines in viewWillAppear
in my CustomViewController.
[self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
[self.navigationController.navigationBar setTranslucent:NO];
For Swift2.x this works:
self.navigationController?.navigationBar.barTintColor = UIColor.redColor()
For Swift3.x this works:
self.navigationController?.navigationBar.barTintColor = UIColor.red