iOS状态栏颜色修改

1.此方法是设置状态栏整个背景颜色
- (void)setStatusBarBackgroundColor:(UIColor *)color
{
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
}

2.此方法可以直接设置状态栏文字白色
OC
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
Swift
override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
}

extension UINavigationController {
    open override var childViewControllerForStatusBarStyle: UIViewController? {
        return topViewController
    }
}

你可能感兴趣的:(iOS状态栏颜色修改)