Swift version: 5.10
As of iOS 7.0, all view controllers set their own status bar style by default, which means they can have black text or white text depending on what looks best for your view controller. If you want to have light text in the status bar, add this code to your view controller:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
If you want to change the status bar color dynamically, you should call setNeedsStatusBarAppearanceUpdate()
on your view controller, which will force preferredStatusBarStyle
to be read again. Pro tip: you can put setNeedsStatusBarAppearanceUpdate()
inside an animation block to have the change animate.
SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Available from iOS 7.0
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.