How can I hide the status bar in iOS 7.1?

In iOS 7.0, I hid the status bar in my apps by adding

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

to the info.plist. I just updated my testing iPad to iOS 7.1, and the status bar is now back in all of my apps. How can I hide it in both 7.0 and 7.1?

  • Cancel button is not shown in UISearchBar
  • How to use iOS Simulator 7 \ XCode 5 to test pre-iOS 7 UI (without upgrading the app for iOS 7)
  • Get the date of sunday of the current week in IOs
  • Xcode 9 crashes when debugging in swift
  • UICollectionView does not scroll
  • how to change uilabel text size in different iPhones
  • Update: This is only happening in iPhone apps running on the iPad, I don’t see this problem on the iPhone or in the simulator.

    5 Solutions Collect From Internet About “How can I hide the status bar in iOS 7.1?”

    Try adding the following

       - (void)viewWillAppear:(BOOL)animated{
            NSLog(@"View will appear");
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
    
        }
    
        - (void)viewWillDisappear:(BOOL)animated{
    
            [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
        }
    

    I can reproduce the problem with a single-view iPhone-only app running in iPhone-compatibility mode in the simulator. But only when selecting an iPad non-retina on iOS 7.1.

    My findings:

    • The status bar will not be hidden, whatever you specified in the plist or in code.
    • The problem doesn’t occur on retina iPads
    • The problem doesn’t occur on iOS 7 or iOS 6

    I tried these keys in the .plist:

    <key>UIStatusBarHidden</key>
    <true/>
    <key>UIStatusBarHidden~ipad</key>
    <true/>
    

    and

    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>UIViewControllerBasedStatusBarAppearance~ipad</key>
    <false/>
    

    I also tried the ViewController based-solution as mentioned by @Irfan to no avail.

    There also seems no way to detect if the statusbar is shown as [UIApplication sharedApplication].statusBarFrame returns {0, 0, 0, 0}

    In the view controllers in which you want the status bar hidden, add the following method

    - (BOOL)preferStatusBarHidden {
      return YES;
    }
    

    Then you can call

    [self setNeedsStatusBarAppearanceUpdate];
    

    which will fire the change to the status bar. This call can be done inside of an animation block which will animate the change.

    Add this to ViewDidLoad:

     [[UIApplication sharedApplication] setStatusBarHidden:YES
                                            withAnimation:UIStatusBarAnimationFade];
    

    And Implement below Method:

    - (BOOL)prefersStatusBarHidden {
    return YES;
     }
    

    It will hide status-bar of that particular ViewController in which you Implement it.
    It works superbly good for me.
    Hopefully it will also help you out.

    The only solution I have found to this is to add the following:

    - (UIStatusBarStyle) preferredStatusBarStyle {
        return -1;
    }
    

    wherever you have:

    - (BOOL)prefersStatusBarHidden {
        return YES;
    }
    

    This is obviously terrible, but it seems to work for me — at least so far.

    UPDATE: I have noticed this causing output like the following:

    <Error>: CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
    

    I find another workaround, and it’s possible that this error is what makes this workaround work, so I’m sticking with it, but it’s worth noting.