the font for the status bar is black: Uistatusbarstyledefault
the font for the status bar is white: Uistatusbarstylelightcontent
first, in info.plist , set the View controller-based status bar appearance to NO
The color of the status bar font is set only by the following property, which is white by default:
Default is Uistatusbarstyledefault
[UIApplication Sharedapplication].statusbarstyle
How to solve the different color of status bar font in individual VC
1. In Info.plist, set the view controller-based status bar appearance to No.
2, in the app delegate:
[UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;
3, in the individual status bar font color is not the same VC
-(void) Viewwillappear: (BOOL) animated{
[UIApplication sharedapplication].statusbarstyle = Uistatusbarstyledefault;
}
-(void) Viewwilldisappear: (BOOL) animated
{
[Super viewwilldisappear:animated];
[UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;
}
second, in info.plist , the View controller-based status bar appearance is set to YES, or not set.
The default value for View controller-based status bar appearance is yes.
If view controller-based status bar appearance is yes.
The [uiapplication Sharedapplication].statusbarstyle is invalid.
Use the following method:
1, in the VC rewrite VC Preferredstatusbarstyle method.
-(Uistatusbarstyle) Preferredstatusbarstyle
{
return uistatusbarstyledefault;
}
2. Call in Viewdidload: [Self setneedsstatusbarappearanceupdate];
However, when the VC in Nav, the above method is useless , VC Preferredstatusbarstyle method does not have to be called.
The reason is that [self setneedsstatusbarappearanceupdate] is issued,
Only the Preferredstatusbarstyle method in the navigation controller is called.
The Preferredstatusbarstyley method in VC will not be called.
There are two solutions:
Method One:
Setting the Barstyle property of NavBar affects the font and background color of the status bar. As follows.
The font for status bar is white
The background color of the navigation bar is black.
Self.navigationController.navigationBar.barStyle = Uibarstyleblack;
The font for status bar is black
The background color of the navigation bar is white, and the background color of the status bar is white.
Self.navigationController.navigationBar.barStyle = Uibarstyledefault;
Method Two:
Customize the subclass of a nav bar, overriding the Preferredstatusbarstyle method in this subclass:
mynav* nav = [[Mynav alloc] INITWITHROOTVIEWCONTROLLER:VC];
Self.window.rootViewController = nav;
@implementation Mynav
-(Uistatusbarstyle) Preferredstatusbarstyle
{
uiviewcontroller* TOPVC = Self.topviewcontroller;
return [TOPVC Preferredstatusbarstyle];
}