How to Hide a Status Bar in Ios

Hide Status Bar In iOS 8 app

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

How to hide a status bar in iOS?

Add the following code to your view controller:

if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}

- (BOOL)prefersStatusBarHidden {
return YES;
}

Hide the status bar in ios 9

Swift-3

 override var prefersStatusBarHidden: Bool {  
return true
}

I got the Information From Here

  • Change func to var

  • Delete ()

  • Change -> to :

This works because a computed variable has a getter function, so the function you were implementing before simply turns into the getter function


2016 onwards: simple Thing like

On your info.plist add the following two property for statusBar Hidden

View controller-based status bar appearance (Boolean: NO)

Status bar is initially hidden (Boolean: YES)

By Source

UIStatusBarHidden

UIViewControllerBasedStatusBarAppearance

or

Sample Image


Old answers ! ...

  1. add application.statusBarHidden in didFinishLaunchingWithOptions

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    application.statusBarHidden = YES;
    return YES;
    }

and add


  1. in info.plist add this View controller-based status bar appearance set NO

    View controller-based status bar appearance = NO

viewcontroller based hidden set

Add method in your view controller.

Objective -C

- (BOOL)prefersStatusBarHidden {
return YES;
}

Swift upto 2

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

(GOOD) 2016.5.17 in iOS 9.0 worked nicely.

Updated Answer

  1. Go to Info.plist file
  2. Hover on one of those lines and a (+) and (-) button will show up.
  3. Click the plus button to add new key
  4. Type in start with capital V and automatically the first choice will be View controller-based status bar appearance. Add that as the KEY.
  5. Set the VALUE to "NO"
  6. Go to you AppDelegate.m for Objective-C (for swift language: AppDelegate.swift)
  7. Add the code, inside the method

For Objective-C:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setStatusBarHidden:YES];

return YES;
}

For Swift:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
application.statusBarHidden = true

return true
}

Hide Status Bar in iOS 13

Step 1 :- add permission

Sample Image

Step 2 :- add the below code in desired view controller to hide the status bar .

override var prefersStatusBarHidden: Bool {
return true
}

NOTE :- if you don't set constrain properly after the hidden true / false you will have design issues , so take care about it ...:)

How do I hide the status bar in a Swift iOS app?

You really should implement prefersStatusBarHidden on your view controller(s):

Swift 3 and later

override var prefersStatusBarHidden: Bool {
return true
}

How to programmatically hide and show status bar in iOS 13?

If you want to show/hide the status bar on the different View Controllers you need to:

  1. Add View controller-base status bar appearance option in your Info.plist and set it to YES
  2. Override var prefersStatusBarHidden: Bool in each View Controller where you want to have the status bar shown/hidden
override var prefersStatusBarHidden: Bool { 
return true
}

If you want to show/hide it dynamically (ex. after tapping on button), you could do something like this:

var statusBarHidden = true {
didSet {
setNeedsStatusBarAppearanceUpdate()
}
}

override var prefersStatusBarHidden: Bool {
return statusBarHidden
}
  • You could find more verbose explanation here Here

  • Also in the Apple Documentation for UIStatusBarManager you can find the following quote:

You do not use this object to modify the configuration of the status bar. Instead, you set the status bar configuration individually for each of your UIViewController objects. For example, to modify the default visibility of the status bar, override the prefersStatusBarHidden property of your view controller.

How to hide the app status bar

Turns out I was previously compensating for the status bar being there with:

webView.scrollView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)

changed the top value to 0 and along with the 5 steps in the question and that has worked.

Hide statusbar during splash screen

This is updated for Swift 3 of Xcode 8.3.3

In your Info.plist add the following key:

info.plist

Then in your AppDelegate file add the following in didFinishLaunchingWithOptions section:

func application(_application:UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
UIApplication.shared.isStatusBarHidden = false
return true
}

That should sort out your problem.

You can also configure the launch colour in your project Build Settings if this is a problem for you:

buildOptions

Hope that helps!



Related Topics



Leave a reply



Submit