Swift version: 5.6
You can hide the status bar in any or all of your view controllers just by adding this code:
override var prefersStatusBarHidden: Bool {
return true
}
Any view controller containing that code will hide the status bar by default.
If you want to animate the status bar in or out, just call setNeedsStatusBarAppearanceUpdate()
on your view controller – that will force prefersStatusBarHidden
to be read again, at which point you can return a different value. If you want, your call to setNeedsStatusBarAppearanceUpdate()
can actually be inside an animation block, which causes the status bar to hide or show in a smooth way.
SPONSORED An iOS conference hosted in Buenos Aires, Argentina – join us for the third edition from November 29th to December 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.