StatusBarBackgroundColor在ios不生效 , 调用原生ios方法设置状态栏颜色

// 设置状态栏颜色
- (void)setStatusBarBackgroundColor:(UIColor *)color {
    
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
}

// !!!重点在viewWillAppear方法里调用下面两个方法(看情况,可以在viewDidLoad中调用)
-(void)viewWillAppear:(BOOL)animated{
    // 设置状态栏颜色
    [self setStatusBarBackgroundColor:[UIColor colorWithRed:21/255.0 green:21/255.0 blue:21/255.0 alpha:1.0]];
    // 设置状态栏字体颜色白色(UIStatusBarStyleDefault是黑色)
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
--->!!!同时别忘了在info plist里面将View controller-based status bar appearance设置成NO(默认是YES)

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
  }

你可能感兴趣的:(ios进阶)