Sometimes we need to change the color of the status bar font based on different backgrounds, my method is more complicated, if there is a better way to welcome everyone to propose, I will continue to update.
#方法一
1. First, set the Info.plist file:
Set the value of view controller-based status bar appearance to No.
2. In the APPDELEGATE.M method, the following settings, the default will be shown black equals to your app status bar set a main color
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {
Set the global status bar font color to black
[UIApplication sharedapplication].statusbarstyle = Uistatusbarstyledefault;
Set global status bar font color to white
[UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;
return YES;
}
3. Add the following code where it needs to be set to white:
[UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;
4. Add the following code where you need to change back to black:
[UIApplication sharedapplication].statusbarstyle = Uistatusbarstyledefault;
For example, you want to set the font color of a controller's status bar to the white code as follows:
#pragma mark-Set the status bar color
-(void) Viewwillappear: (BOOL) animated{
[Super viewwillappear:animated];
[UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;
}
-(void) Viewwilldisappear: (BOOL) animated
{
[Super viewwilldisappear:animated];
[UIApplication sharedapplication].statusbarstyle = Uistatusbarstyledefault;
}
It is important to note that in Uitabbarcontroller, if each page of the tab is loaded, the Viewwillappear method of the next page is called when you switch the page, and then the Viewwilldisappear method of this page is called. Affects the font color change in the status bar.
IOS Modify status bar font Color (pro-test, easy to use)