1.首先,苹果把UIViewControllerBasedStatusBarAppearance默认的值设为YES,是有他的道理的,新系统下,苹果希望我们的viewcontroller去控制status bar,也就是说,我们大多数的界面应该是统一的,偶尔一些viewcontroller需要status bar特殊控制的,完全交给当前的viewcontroller来做。
2.放在不同的controller去改变每个页面的状态栏颜色
#pragma mark - Status Bar
Where UIStatusBarStyleDefault
is dark content, for use on light backgrounds andUIStatusBarStyleLightContent
is for light content, for use on dark backgrounds.
You might need to call [self setNeedsStatusBarAppearanceUpdate];
in the viewDidLoad to inform the system of a change.
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
}
- (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleDefault; //默认黑色 return UIStatusBarStyleLightContent; //白色 } - (BOOL)prefersStatusBarHidden { return _isFullScreen; } - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation { return UIStatusBarAnimationSlide; }
3.刷新
[UIView animateWithDuration:.3 animations:^{ if (ISIOS7) { [self setNeedsStatusBarAppearanceUpdate]; } }];
二, 设置全局的所有页面状态栏颜色
2. 在infoPlist里设置UIViewControllerBasedStatusBarAppearance为NO,然后在代码里添加:
[application setStatusBarStyle:UIStatusBarStyleLightContent];