cdub
cdub

Reputation: 25751

Hide the status bar in ios 9

How do you hide the status bar in ios 9?

This is now deprecated:

 [UIApplication sharedApplication] setStatusBarHidden:YES];

Upvotes: 33

Views: 52536

Answers (7)

daris mathew
daris mathew

Reputation: 429

An easy approach would be to set the windowLevel of the Application to be either normal or statusBar based on your needs, so to start

Objective-C

To Hide the Status Bar

 UIApplication.sharedApplication.keyWindow.windowLevel = UIWindowLevelStatusBar;

To Show the Status Bar

 UIApplication.sharedApplication.keyWindow.windowLevel = UIWindowLevelNormal;

Also add the Key (View controller-based status bar appearance) with boolean value NO.

enter image description here

Upvotes: 2

budiDino
budiDino

Reputation: 13557

If for some reason you need View controller-based status bar appearance equal to YES (for example to keep status bar white)

on AppDelegate's didFinishLaunchingWithOptions method or wherever you setup your navigationController:

yourNavigationController.navigationBar.barStyle = .black

then use alex-staravoitau's awesome answer and add this code wherever you'll be hiding the status bar:

override var preferredStatusBarStyle: UIStatusBarStyle {
  return .lightContent
}

I'm not sure if this is the right way to achieve this result, but it worked for me and I hope it helps someone else too :)

Upvotes: 1

emraz
emraz

Reputation: 1613

In most of the iOS it will work. I have tested with iOS 10.

  1. Open info.plist
  2. "View controller-based status bar appearance" set to NO
  3. "Status bar is initially hidden" set to YES
  4. Done

Upvotes: 0

Anbu.Karthik
Anbu.Karthik

Reputation: 82766

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

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

or

enter image description here


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
}

Upvotes: 82

Andrey Gordeev
Andrey Gordeev

Reputation: 32549

Here's how do you easily return a control over status bar visibility for iOS 9+ and Swift 3+:

  1. Add View controller-based status bar appearance key with YES value to Info.plist.
  2. Add this variable to the view controller:

    private var isStatusBarHidden = false {
        didSet {
            setNeedsStatusBarAppearanceUpdate()
        }
    }
    
  3. Override prefersStatusBarHidden property:

    override var prefersStatusBarHidden: Bool {
        return isStatusBarHidden
    }
    

That's it. Now you are able to call isStatusBarHidden = true and isStatusBarHidden = false whenever you want.

Upvotes: 6

Jamil
Jamil

Reputation: 2999

in info.plist add the following two property.

View controller-based status bar appearance (NO)

Status bar is initially hidden (YES)

Upvotes: 16

rckoenes
rckoenes

Reputation: 69499

I know that the documentation of setStatusBarHidden: does not mention on what use instead. But the header of UIApplication does.

// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
@property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController prefersStatusBarHidden]");
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_DEPRECATED_IOS(3_2, 9_0, "Use -[UIViewController prefersStatusBarHidden]");

Here is stated that you should use the prefersStatusBarHidden on UIViewController and use view controller based statusbar styles.

All you need to do now is configure whether the view controller needs to show of hide the status bar. Like so :

- (BOOL)prefersStatusBarHidden {
   return YES;
}

Upvotes: 7

Related Questions