I usually hide the status bar with
override func prefersStatusBarHidden() -> Bool {
return true
}
but Xcode is giving me an error, saying "Method does not override anything from its superclass".
If I delete the override
, Xcode gives a different error: "Method 'prefersStatusBarHidden()' with Objective-C selector 'prefersStatusBarHidden' conflicts with getter for 'prefersStatusBarHidden' from superclass 'UIViewController' with the same Objective-C selector"
I also have "Hide Status Bar" checked in my Target's general settings:
but the status bar still shows up.
I found this method in another Stack Overflow answer
UIApplication.shared.setStatusBarHidden(true, with: .none)
but that doesn't hide the status bar either.
In Xcode 8 Beta 1, I used the first and second methods, which worked to hide the status bar (the first method did not return an error). What can I do now to hide the status bar, with Xcode 8 Beta 4?
Note: The status bar shows up on Simulator devices and physical devices, all running iOS 10.
We need to override the property itself on Swift 3 (this is new in Xcode 8 Beta 4):
override var prefersStatusBarHidden: Bool {
return true
}
updated Swift 5+
override var prefersStatusBarHidden: Bool { true }
for another example also you can get here and here
For more on what this change is and why it's necessary, see Matt's great answer on this.