美文网首页
#pragma mark - 改变statusBar颜色变化

#pragma mark - 改变statusBar颜色变化

作者: 三岁就很乖 | 来源:发表于2020-07-16 16:27 被阅读0次

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

[图片上传中...(IMG_9847.jpg-6a2944-1594888797336-0)] IMG_9847.jpg
-(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;
}

相关文章

网友评论

      本文标题:#pragma mark - 改变statusBar颜色变化

      本文链接:https://www.haomeiwen.com/subject/zzywohtx.html