Hide the status bar in ios 9
Asked Answered
G

7

33

How do you hide the status bar in ios 9?

This is now deprecated:

 [UIApplication sharedApplication] setStatusBarHidden:YES];
Gissing answered 6/10, 2015 at 8:51 Comment(2)
Possible duplicate of Cannot hide status bar in iOS7Madwort
Possible duplicate of How to hide a status bar in iOS?Cleora
E
82

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
}
Emeritaemeritus answered 6/10, 2015 at 8:57 Comment(9)
@AshishKakkad -- I updated my answer, thanks a lot my friendEmeritaemeritus
@AshishKakkad -- i am not face error iOS9, can u explain what are the errors,if I face its usefulor meEmeritaemeritus
@AshishKakkad -- tanx my friend, in future if I face the issue , i surely use your answerEmeritaemeritus
I don't think you want or need to add View controller-based status bar appearance = NO to you info.plist. This will trigger an error message. Adding the one line of code to your app delegate is sufficient for me.Tamarah
application.statusBarHidden is deprecated in iOS 9Torrell
@JoeBlow - tanx buddy thats my old answer I updated answer verify onceEmeritaemeritus
"(GOOD) 2016.5.17 in iOS 9.0 worked nicely." - But it's not working on SDK 9.0.Wiretap
Love your answer...perfectly collected.Terena
@ajniN - happy to hearEmeritaemeritus
A
16

in info.plist add the following two property.

View controller-based status bar appearance (NO)

Status bar is initially hidden (YES)
Aluminiferous answered 6/10, 2015 at 9:7 Comment(3)
Just overriding the preferredStatusBarHidden method did not work. Adding this finally did it for me. Thanks a lot!Stopper
this is simply the correct and only answer for 2016+. FINALLY apple fixed this idiotic problem. Cheer!Disuse
hat tip to you.Unprecedented
S
7

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;
}
Stinkweed answered 6/10, 2015 at 8:56 Comment(2)
But what if want to hide status bar on tap event of any button in VeiwController ?Pani
@Pani you might want to ask this question as a new topic and not a comment on an answer.Stinkweed
S
6

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.

Stegall answered 11/10, 2016 at 7:22 Comment(0)
M
2

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

Marry answered 25/7, 2018 at 11:33 Comment(0)
P
1

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 :)

Paludal answered 23/12, 2016 at 3:42 Comment(1)
This is a very helpful answer. If you need fine control throughout the app this is the way to go. I didn't need to do anything in the AppDelegate though.Syndicate
S
0

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
Sanmiguel answered 3/5, 2017 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.