Xcode Hide ios 10 white status bar

I want a status bar in my application. To do this, I set the View controller-based status bar appearance to NO and the Status bar style to UIStatusBarStyleLightContent . But now I need to hide the status bar in some controllers. To hide this, I have to set the View controller-based status bar appearance to YES and add - (BOOL)prefersStatusBarHidden {return YES;} . But now the status bar is black. It is black if View controller-based status bar appearance YES and white if NO . So the question is how to set the white status bar and hide it?

UPD: code in VC that I want to have a white status bar ( prefferdSTatusBarStyle not called)

enter image description here

code in VC with hidden status bar

enter image description here

Settings

.plist

enter image description here

The result is a black status bar that is hidden in some VC

UPD2:

I know that it is bad to use obsolete methods, but with [[UIApplication sharedApplication] setStatusBarHidden:YES]; everything works the way i want. If anyone has a better solution, please let me know.

+5
source share
5 answers

you can set using the xcode status bar style to be "light"

enter image description here

0
source

This is the quick version:

To hide the status bar or change its appearance, you need to override the following properties in your view controller itself.

 override var prefersStatusBarHidden: Bool{ return true } 

the above hides the status bar and below if you want to set it to white:

 override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } 
+3
source

In your plist file, add the View controller-based status bar appearance Bool property and set it to YES.

Now in your view the controller will add the following methods:

 // TO MAKE STATUS BAR WHITE override func preferredStatusBarStyle() -> UIStatusBarStyle { return .LightContent } // TO MAKE STATUS BAR BLACK override func preferredStatusBarStyle() -> UIStatusBarStyle { return .LightContent } // RETURN TRUE TO HIDE AND FALSE TO SHOW STATUS BAR override func prefersStatusBarHidden() -> Bool { return true } 

For Objective-C

 - (BOOL)prefersStatusBarHidden { return NO; } -(UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } 

To remove redundant code, you can make BaseViewController a subclass of UIViewController and add methods to this class. And override the method in the class that needs to be changed.

+2
source

if your viewcontroller is built into the UInavigationController, try writing this code in

 -(BOOL)prefreStatusBarHidden { return [self.navigationController prefersStatusBarHidden]; } 
0
source

You can do this by setting a navigation background image in your base controller.

 UIImage *bgImage = [UIImage imageNamed:@"bg_navigationbar"]; [self.navigationController.navigationBar setBackgroundImage:bgImage forBarMetrics:UIBarMetricsDefault]; 
-1
source

Source: https://habr.com/ru/post/1262859/


All Articles