1.首先是設(shè)置info.plist 文件:
將View controller-based status bar appearance 的值設(shè)置為NO。
2.在AppDelegate.m 的方法中如下設(shè)置,默認(rèn)會顯示黑色等于為你的app狀態(tài)欄設(shè)置一個主顏色
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
????//設(shè)置全局狀態(tài)欄字體顏色為黑色???
?????[UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleDefault;
????//設(shè)置全局狀態(tài)欄字體顏色為白色
????// [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
????returnYES;
}
3.在需要設(shè)置為白色的地方添加如下代碼:
[UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleLightContent;
4.在需要變回黑色的地方添加如下代碼:
[UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleDefault;
例如你想將一個控制器的狀態(tài)欄的字體顏色設(shè)為白色代碼如下:
#pragma mark - 設(shè)置狀態(tài)欄顏色
-(void)viewWillAppear:(BOOL)animated{? ?
?????[superviewWillAppear:animated];? ?
?????[UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleLightContent;? ?
?}
-(void)viewWillDisappear:(BOOL)animated{? ? ??
????? [superviewWillDisappear:animated];? ? ? ?
?????[UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleDefault;?
?}