48

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.

Erik Godard
  • 5,930
  • 6
  • 30
  • 33
owlswipe
  • 19,159
  • 9
  • 37
  • 82
  • Check this answer http://stackoverflow.com/a/31129671/5109911 – Marco Santarossa Aug 10 '16 at 14:32
  • @SaintThread Thank you but see the first part of my question about why using `func prefersStatusBarHidden` just isn't working. Any other ideas? – owlswipe Aug 10 '16 at 14:37
  • @matt I don't think this is a duplicate because that answer is explicitly about interface orientation, which is different than what I'm talking about here. It also doesn't cover the `get { return true }` covered here, and doesn't cover the other types of methods that failed for me. It's just not complete enough to be an answer for my question. – owlswipe Aug 10 '16 at 14:49
  • 1
    @JohnRamos Did you even _read_ my answer? It happens that the _question_ was about interface orientation, but my _answer_ covers your situation exactly, explaining what has changed in Swift 3 Xcode 8 seed 4 (i.e. certain view controller methods are now properties that you override as properties). My answer is _extremely_ complete and explicitly includes `prefersStatusBarHidden`. – matt Aug 10 '16 at 15:09
  • @matt I did indeed read your answer and saw that it included a prefersStatusBarHidden reference. I just don't think it covers with such simplicity and specificity the particular topic at hand as does Anbu's answer (which I edited to include a more info reference to your detailed answer). I agree that your answer could work with some edits as an answer to this question, I just don't think it quite fits as is. I just don't think this unique question deserves a [duplicate] tag given how different your answer and its accompanying question is to my question and its accepted answer here. – owlswipe Aug 11 '16 at 02:17
  • [set status bar with code dynamically](http://stackoverflow.com/q/43752721/6521116) – LF00 May 15 '17 at 08:29
  • @KrisRoofe Indeed, your question is a duplicate of this one. – owlswipe May 15 '17 at 19:05
  • @owlswipe, no in my quesiton I need to hide or show with user event. Not config it to the stable status. – LF00 May 16 '17 at 01:45
  • 1
    @KrisRoofe Ok, my bad. Cool stuff. – owlswipe May 16 '17 at 02:52

1 Answers1

111

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.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143