Swift version: 5.6
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 Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until October 1st.
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.