Sometimes, when building an iOS app you may notice that the status bar color doesn't match your app's background. This can make it difficult for users to see status bar icons and text. It also might not look that great! Fortunately, it's easy to change the status bar color by simply configuring your Info.plist file.
To customize your app's status bar color, add the following properties to your Info.plist file:
UIViewControllerBasedStatusBarAppearance
(View Controller-Based Status Bar Appearance): This property must be set to false
in order to customize status bar text and icon color.UIStatusBarStyle
(Status Bar Style): You may set this key to UIStatusBarStyleLightContent
for dark text on a light background or UIStatusBarStyleDarkContent
for light text on a dark background.If you need to programmatically change the status bar color, you can do so by using the following code in your View Controller:
override func viewDidLoad() {
super.viewDidLoad()
self.setNeedsStatusBarAppearanceUpdate()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .darkContent // or .lightContent
}
That's it! You now know what it takes to change your app's status bar text color either through your project's plist file or directly through code.