1、利用kvc
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self setStatusBarBackgroundColor:[UIColor redColor]];
}
//设置状态栏颜色
- (void)setStatusBarBackgroundColor:(UIColor *)color {
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self setStatusBarBackgroundColor:[UIColor clearColor]];
}
如图
修改了状态栏颜色
网友评论