If the UIViewController is currently displayed, you may need to change the foreground color of statusBar from time to time on the current page, first, you need to call the following setNeedsStatusBarAppearanceUpdate method (this method will notify the system to call the preferredStatusBarStyle method of the current UIViewController). This is similar to the setNeedsDisplay principle of UIView (call the setneedsdis, when the system refresh the page next time, it calls to re-paint the view. The system can refresh the page 60 times in one second, depending on the program settings ).-(UIViewController *) childViewControllerForStatusBarStyle:
This interface is also very important. The default return value is nil. When setNeedsStatusBarAppearanceUpdate is called, The system calls application. the preferredStatusBarStyle method of rootViewController in window. In our program, UINavigationController is generally used as the root. In this case, the preferredStatusBarStyle in our UIViewController will not be called at all;
In this case, childViewControllerForStatusBarStyle comes in handy,
We want to subclass A UINavigationController. In this subclass, override the childViewControllerForStatusBarStyle method as follows:
- (UIViewController *)childViewControllerForStatusBarStyle{ return self.topViewController;}
The above code means not to call the preferredStatusBarStyle method of myself (that is, UINavigationController), but to call navigationController. the preferredStatusBarStyle method of topViewController. In this way, the preferredStatusBarStyle method of UIViewController currently displayed can affect the foreground part of statusBar.
In addition, sometimes our currently displayed UIViewController may have multiple childviewcontrollers, which overwrite the current callback method of UIViewController to bring the preferredStatusBarStyle of childViewController into effect (the preferredStatusBarStyle of UIViewController will not be called ).
To put it simply, as long as the callback method returned by UIViewController is not nil, The preferredStatusBarStyle method of UIViewController will not be called by the system. The system will call the preferredStatusBarStyle method returned by childViewControllerForStatusBarStyle.
-(Void) setNeedsStatusBarAppearanceUpdate:
The system calls the preferredStatusBarStyle method of rootViewController of application. window. If the return value of childViewControllerForStatusBarStyle of rootViewController is not nil, refer to the above description.
Set the background of statusBar]The background is the background color. There are two ways to change the background color:
Methods provided by the systemSetBarTintColor interface of navigationBar. This interface can be used to change the background color of statusBar.
Note: Once the navigationBar-(void) setBackgroundImage :( UIImage *) backgroundImage forBarMetrics :( UIBarMetrics) barMetrics interface is set, the above setBarTintColor interface cannot change the background color of statusBar, the background color of statusBar is black.
A different pathCreate a UIView,
Set the frame. size of the UIView to the same size as the statusBar,
Set frame. origin of the UIView to {0,-20 },
Set the background color of the UIView to the color of your desired statusBar,
On the navigationBar, addSubView the UIView.
Refer:
Information Property List Key Reference: iOS Keys
New features that are easily overlooked in iOS7-CocoaChina Chinese site developed by Apple