iOS状态栏颜色修改

2017-05-12  本文已影响26人  薄凉_简书
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
    }
}
上一篇下一篇

猜你喜欢

热点阅读