Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Status Bar In iOS 8 app

I have tried

[[UIApplication sharedApplication] setStatusBarHidden:YES];  

This does nothing.

And I have looked in my Info.plist file for "View controller-based status bar appearance" but it's not there.

How can I hide the white status bar at the top of the screen (with the clock and battery charge) inside my app for Xcode 6? Thank you!

like image 381
Aggressor Avatar asked Oct 01 '14 16:10

Aggressor


People also ask

How do I hide the status bar on my iPhone 8?

To completely hide it on the home screen, open up an app, such as Settings, and wait about three to four seconds. Press the home button again, and the status bar will be completely gone.

How do I hide the app bar on my iPhone?

Open Settings > Accessibility > Guided Access. On the Guided Access screen, toggle the switch to On. Select the options that appear when Guided Access is enabled.


1 Answers

You need to override this method on each view controller unless you have that plist entry.

Objective-C

-(BOOL)prefersStatusBarHidden{     return YES; } 

Swift 2

override func prefersStatusBarHidden() -> Bool {     return true } 

Swift 3+

override var prefersStatusBarHidden: Bool {     return true } 

And don't forget to set (if you present a view controller by calling the presentViewController:animated:completion: method):

Objective-C

vcToBeShownWithoutStatusbar.modalPresentationCapturesStatusBarAppearance = YES; 

Swift

vcToBeShownWithoutStatusbar.modalPresentationCapturesStatusBarAppearance = true 

Documentation: https://developer.apple.com/reference/uikit/uiviewcontroller/1621453-modalpresentationcapturesstatusb

If you change status bar from some container view controller (eg. UINavigationController or UIViewController with child view controllers) and you would like to change view controller responsible for status bar you should use childViewControllerForStatusBarHidden: property. Eg:

Set first view controller instance always responsible for status bar management

Objective-C

- (UIViewController *)childViewControllerForStatusBarHidden {     return childViewControllers.first; // or viewControllers.first } 

Swift 2

override var childViewControllerForStatusBarHidden() -> UIViewController? {     return childViewControllers.first // or viewControllers.first } 

Swift 3+

override var childViewControllerForStatusBarHidden: UIViewController? {     return childViewControllers.first // or viewControllers.first } 

Set container view controller responsible for status bar management

Objective-C

- (UIViewController *)childViewControllerForStatusBarHidden {     return nil; } 

Swift 2

override func childViewControllerForStatusBarHidden() -> UIViewController? {     return nil } 

Swift 3+

override var childViewControllerForStatusBarHidden: UIViewController? {     return nil } 

Documentation: https://developer.apple.com/documentation/uikit/uiviewcontroller/1621451-childviewcontrollerforstatusbarh

like image 91
VaporwareWolf Avatar answered Sep 22 '22 07:09

VaporwareWolf