Detailed explanation of UIViewControllerBasedStatusBarAppearance in ios7
When adapting to iOS7, many articles mention UIViewControllerBasedStatusBarAppearance. I have never understood its actual function very much. When using it, I found that the actual function of UIViewControllerBasedStatusBarAppearance is as follows:
This property only affects how to set whether the color of the font on the status bar is dark (black) or bright (white), and has no effect on the background color of the status bar. The background color of the status bar is always transparent on iOS7.
Apple's official explanation of UIViewControllerBasedStatusBarAppearance:
UIViewControllerBasedStatusBarAppearance (Boolean - iOS) specifies whether the status bar appearance is based on the style preferred by the view controller that is currently under the status bar. When this key is not present or its value is set to YES, the view controller determines the status bar style. When the key is set to NO, view controllers (or the app) must each set the status bar style explicitly using the UIApplication object.
That is: UIViewControllerBasedStatusBarAppearance (a Boolean value) specifies whether the appearance of the status bar is based on the preferred style specified by the current view controller to the status bar. When this key does not exist, or its value is set to YES (that is, the default value of this key is yes), the view controller determines the style of the status bar. When the key is set to NO, the view controller (or application) must display the setting status bar style through the UIApplication object (i.e. the setStatusBarStyle method of UIApplication).
It is not difficult to see through the official Apple documentation that on iOS7, there are only two ways to set the status bar style (dark or bright colors). The first is to return the status bar style through the callback method preferredStatusBarStyle in the controller, and the second is to set the setStatusBarStyle of the UIApplication object. UIViewControllerBasedStatusBarAppearance actually specifies whether to use the first method first (this is not difficult to understand why this key value is called UIViewControlle "based").
So when there is no UIViewControllerBasedStatusBarAppearance key in the plist, or this key exists, and the value is YES,
The preferredStatusBarStyle method of viewController takes effect on the setting of the status bar;
When the value corresponding to UIViewControllerBasedStatusBarAppearance is NO,
[UIApplication sharedApplication] The setting of the status bar takes effect through the method setStatusBarStyle.
Hide status bar
Sometimes we need to hide the status bar, so at this time we override method prefersStatusBarHidden: in the view controller, as shown in the following code:
- (BOOL)prefersStatusBarHidden { return YES; }
Thank you for reading, I hope it can help you. Thank you for your support for this site!