美文网首页
iOS状态栏颜色修改

iOS状态栏颜色修改

作者: 薄凉_简书 | 来源:发表于2017-05-12 15:27 被阅读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
    }
}

相关文章

网友评论

      本文标题:iOS状态栏颜色修改

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