Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Hide Status Bar—Swift 3, [duplicate]

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:

enter image description here

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.

like image 767
owlswipe Avatar asked Aug 10 '16 14:08

owlswipe


1 Answers

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.

like image 119
Anbu.Karthik Avatar answered Nov 19 '22 13:11

Anbu.Karthik