IOS modifies the font color of the status bar and modifies the background color of the status bar

About the status bar of some knowledge, but also in contact with the product demand after careful study, research, the following code and analysis, is their own access to information and operation practices after summing up

1 modify the font color of the status bar (set up to display battery power, time, the color of the part of the network)

1): Method 1

Step one: call the [UIApplication sharedApplication] Info.plist (Build Setting in a single case next to the addition of View in controller-based status) and bar appearance is set to NO step two: modify the status bar in the ViewController set (need to modify the status bar according to the demand of the style of:[[UIApplication sharedApplication] or [[UIApplication setStatusBarStyle:UIStatusBarStyleLightContent]); sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
IOS modifies the font color of the status bar and modifies the background color of the status bar
status bar Info.plist.png

emphasizes: the default is to use the system base status bar style, and the added View controller-based status bar appearance is the Bool type and defaults to Yes

2) method two

Do other operations, directly set step: modify the status bar according to the demand of the style of self.navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent or self.navigationController.navigationBar.barStyle = UIStatusBarStyleDefault;; step two: re drawing the status bar [self setNeedsStatusBarAppearanceUpdate];
IOS modifies the font color of the status bar and modifies the background color of the status bar
UIStatusBarStyleLightContent.png
IOS modifies the font color of the status bar and modifies the background color of the status bar
UIStatusBarStyleDefault.png
2 hide status bar
Step one: call the [UIApplication sharedApplication] Info.plist (Build Setting in a single case next to the addition of View in controller-based status) and bar appearance is set to NO step two: setting the status bar [[UIApplication sharedApplication] setStatusBarHidden:YES] or [[UIApplication sharedApplication] setStatusBarHidden:NO];
IOS modifies the font color of the status bar and modifies the background color of the status bar
StatusBarHidden.png
3 modify the background color of the status bar (to the hierarchical relationship of the UIWindow)
* change the status bar background color, because of the relatively high level of the status bar, so you can add the following stateView = [[UIView / UIView* effect alloc] initWithFrame:CGRectMake (0, -20, SCREEN_WIDTH, 20) []; self.navigationController.navigationBar addSubview:stateView]; stateView.backgroundColor [UIColor = purpleColor];

Note: because in OC, you should know that UIWindow has three levels, as follows:

UIKIT_EXTERN, const, UIWindowLevel, UIWindowLevelNormal; UIKIT_EXTERN, const, UIWindowLevel, UIWindowLevelAlert; UIKIT_EXTERN, const, UIWindowLevel, UIWindowLevelStatusBar

They are the priority level value corresponding to the UIWindowLevelNormal:0
UIWindowLevelAlert:1000
:
UIWindowLevelStatusBar:2000
(and UIAlertView 1996 levels of priority, the priority level of 2001 UIActionSheet
priority)

4 custom status bar
If the custom status bar, to direct the status bar text, time consumption mark all blocked, you can customize a UIView, then the UIView was added to the UIWindow, as shown below: UIWindow* backWindow = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds]; backWindow.windowLevel = UIWindowLevelStatusBar + 1; / / level is slightly higher than that of UIWindowLevelStatusBar [backWindow becomeKeyWindow]; [backWindow makeKeyAndVisible]; [backWindow addSubview:self]; if in the operation layer, the difference, please read the information, careful handling

Note: if the modified info.plist in accordance with the above steps, still no effect, can try to restart the Xcode… Or try to delete cache files Xcode,
steps as shown below: 1) to start Xcode, click on the ‘command’ key + comma
2) as follows:

IOS modifies the font color of the status bar and modifies the background color of the status bar
step 1.png

3) click in, then select the ‘DerivedData’ file directory, then double-click in, delete all (you can also click Product – &gt, Clean)

Reference document:
changes the status bar (UIStatusBar) color
UIWindow hierarchy