SetStatusBarHidden deprecated in iOS 9.0

I upgrade my code from iOS 8 to iOS 9. I have a piece of code in my program [[UIApplication applicationName] setStatusBarHidden:YES]; .

I get a warning: setStatusBarHidden is deprecated in iOS 9.0, Use is [UIViewController prefersStatusBarHidden ". If I just replaced" setStatusBarHidden "with" prefersStatusBarHidden ", I get an" instance method not found ". Can someone please suggest me how to solve this problem?

+27
objective-c ios9
Jun 29 '15 at 11:20
source share
7 answers

Add the code below to your view controller.

  - (BOOL)prefersStatusBarHidden { return NO; } 

Note:

  • If you change the return value for this method, call setNeedsStatusBarAppearanceUpdate .
  • For childViewController, to indicate that the child view controller should control privileged status, hidden / unclosed state, implement childViewControllerForStatusBarHidden .
+39
Jun 30 '15 at 4:39 on
source share

you need to add a method to your viewController.m

 - (BOOL)prefersStatusBarHidden { return NO; } 
+3
Jun 29 '15 at 12:44
source share

Swift 3.1 Xcode 8.2.1

  • Change the info.plist line. Look at the controller-based status bar and set it to NO.

  • In your target settings, check "Hide status bar"

Both steps required

+2
Feb 21 '17 at 17:00
source share

Swift 3 with Xcode 8.3.3

1) Add a line to Info.plist. enter image description here

2) In your ViewController ViewDidLoad (), override add:

  UIApplication.shared.isStatusBarHidden = true 
+2
Jul 25 '17 at 8:59
source share

Here is my quick code for setting the status bar and style.

 extension UIViewController { public var privateStatusBarHidden: Bool { return statusBarHidden } public var privateStatusBarStyle: UIStatusBarStyle { return statusBarStyle } public func setStatusBarHidden(hidden: Bool, animated: Bool = false) { statusBarHidden = hidden if animated { UIView.animate(withDuration: 0.25, animations: { self.setNeedsStatusBarAppearanceUpdate() }) } else { self.setNeedsStatusBarAppearanceUpdate() } } public func setStatusBar(style: UIStatusBarStyle) { statusBarStyle = style self.setNeedsStatusBarAppearanceUpdate() } public static func swizzleStatusBarHiddenPropertyForViewController() { var original = class_getInstanceMethod(UIViewController.self, #selector(getter: UIViewController.prefersStatusBarHidden)) var changeling = class_getInstanceMethod(UIViewController.self, #selector(getter: UIViewController.privateStatusBarHidden)) method_exchangeImplementations(original, changeling) original = class_getInstanceMethod(UIViewController.self, #selector(getter: UIViewController.preferredStatusBarStyle)) changeling = class_getInstanceMethod(UIViewController.self, #selector(getter: UIViewController.privateStatusBarStyle)) method_exchangeImplementations(original, changeling) original = class_getClassMethod(UIViewController.self, #selector(UIViewController.swizzleStatusBarHiddenPropertyForViewController)) changeling = class_getClassMethod(UIViewController.self, #selector(UIViewController.emptyFunction)) method_exchangeImplementations(original, changeling) } @objc private static func emptyFunction() {} } 

Using

  • in laucing function

UIViewController.swizzleStatusBarHiddenPropertyForViewController ()

  • for hide / show statusBar, in a UIViewController

. self.setStatusBar (hidden: true / false)

+1
Oct 05 '16 at 2:06 on
source share

prefersStatusBarHidden is available from iOS 7+ .

Use this in your UIViewController class

  var isHidden = true{ didSet{ self.setNeedsStatusBarAppearanceUpdate() } } override var prefersStatusBarHidden: Bool { return isHidden } 

enter image description here

If you change the return value for this method, call setNeedsStatusBarAppearanceUpdate (). To indicate that the child, the view manager should monitor the preferred status bar, hidden / unclosed, implements the childViewControllerForStatusBarHidden method.

+1
Nov 14 '17 at 4:34 on
source share

The prefersStatusBarHidden solution does not work.

Which worked instead of [[UIApplication applicationName] setStatusBarHidden: YES];

use

UIApplication.sharedApplication.statusBarHidden = YES;

-one
Nov 20 '17 at 10:12
source share



All Articles