https://blog.csdn.net/sun_cui_hua/article/details/82350268


-(void)viewWillAppear:(BOOL)animated{
self.automaticallyAdjustsScrollViewInsets = NO;
self.navigationController.navigationBar.hidden = YES;
[self setStatusBarBackgroundColor:[UIColor blackColor]];
[UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
}
// 状态栏的样式
//- (UIStatusBarStyle)preferredStatusBarStyle{
// return UIStatusBarStyleDefault;
//}
- (void)setStatusBarBackgroundColor:(UIColor *)color {
if (@available(iOS 13.0, *)) {
UIWindow *keyWindow = [UIApplication sharedApplication].windows[0];
UIView * statusBar = [[UIView alloc] initWithFrame:keyWindow.windowScene.statusBarManager.statusBarFrame];
[keyWindow addSubview:statusBar];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
[self.view addSubview:statusBar];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
} else {
// Fallback on earlier versions
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
}
}
- (void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:self action:nil];
self.navigationController.navigationBar.hidden = NO;
[UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;
}
网友评论