In a ViewController, which I presented modally, I did this:
override func prefersStatusBarHidden() -> Bool {
return true
}
This used
For Swift 3,
override var prefersStatusBarHidden: Bool{
return true
}
and add viewDidLoad()
self.modalPresentationCapturesStatusBarAppearance = true
I'm using Xcode Version 9.2 / Swift 3.2 / iOS 11
I got this answer form BADCloud although I'm not sure why it didn't work for him.
Anyway it worked for me for a specific view controller.
The difference between this answer and the other answers on here is that in my info.plist
when I initially had View controller-based status bar appearance - NO with the 2 statusBar methods below it didn't work but when I changed it to Yes is worked with both of them.
In the info.plist
change:
View controller-based status bar appearance - YES
In the view controller you want it changed in add:
override func viewDidLoad() {
super.viewDidLoad()
// add this in ViewDidLoad
setNeedsStatusBarAppearanceUpdate()
}
// add this underneath ViewDidLoad
override var prefersStatusBarHidden: Bool {
return true
}
For Swift 3 and Swift 4.2 when view going to Appear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIApplication.shared.isStatusBarHidden = true
}
when view goint to Dissapear
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIApplication.shared.isStatusBarHidden = false
}
It's possible you need set in your info.plist, next line:
View controller-based status bar appearance = NO