UIStatusBarStyleLightContentapp
|=UIStatusBarStyleBlackTranslucentide
|=UIStatusBarStyleBlackOpaque動畫
:fa-hand-o-down:info.plist中設置code
<key>UIStatusBarStyle</key> <string>UIStatusBarStyleDefault</string>
:fa-hand-o-down:代碼中設置,須要在UIViewController中重載如下方法ci
//IOS7+ - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } //IOS6+ IOS9.0中廢棄 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
:fa-hand-o-down:用UINavigationController作window.rootViewController時,須要重寫[childViewControllerForStatusBarStyle]方法,[preferredStatusBarStyle]方法纔會被調用animation
- (UIViewController *)childViewControllerForStatusBarStyle{ return self.topViewController; } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; }
:fa-exclamation-circle:[preferredStatusBarStyle]不能直接調用,在須要改變樣式的地方調用: **[self setNeedsStatusBarAppearanceUpdate] **string
在info.plist中設置it
<key>UIViewControllerBasedStatusBarAppearance</key> <false/> <key>UIStatusBarHidden</key> <true/>
View controller-based status bar appearance:io
|-YES:[默認] | View controller對status bar的設置優先級高於application的設置 | 使用[prefersStatusBarHidden] | |-NO: 以application的設置爲準 | view controller的prefersStatusBarHidden方法無效 | 須要用[[UIApplication shareApplication] setStatusBarHidden]
UIViewController中重載sed
- (BOOL)prefersStatusBarHidden { return YES; }
須要調用 [self setNeedsStatusBarAppearanceUpdate] 方法
IOS提供了兩種動畫效果
UIStatusBarAnimationFade
UIStatusBarAnimationSlide
須要重載如下方法:
- (UIStatusBarAnimation )preferredStatusBarUpdateAnimation { return UIStatusBarAnimationSlide; }
可是重載這個方法後,並無動畫效果。這時,咱們須要把 [self setNeedsStatusBarAppearanceUpdate] 放在動畫block中執行:
[UIView animateWithDuration:0.3 animations:^{ [self setNeedsStatusBarAppearanceUpdate]; }];
IOS9以後全部經過application來設置StatusBar的方法都被破棄
IOS7以後推薦使用重載的方式來編輯StatusBar