Swift version: 5.2
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 From January 26th to 31st you can join a FREE crash course for iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a senior developer!
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.