If you want to change the status bar background color and text color you have to perform several steps. In this example we want light text on a dark background.
Change the statusbar text color to white
To change the text color, perform the following steps (not needed when the color of the text must be black):
- Open your storyboard file
- Go to the main navigation controller
- Create a ViewController swift file for it if not available
- Add the following code to it to show white text:
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
Change the statusbar background color
To change the background color of the status bar:
- Open the AppDelegate.swift file and add:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView if statusBar.responds(to: #selector(setter: UIView.backgroundColor)) { statusBar.backgroundColor = UIColor.black } return true }
2. Open the info.plist as Source Code and add:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> ... <key>UIViewControllerBasedStatusBarAppearance</key> <string>NO</string> ... </dict> </plist>