手动更改iOS状态栏的颜色

作者: 司机王 | 来源:发表于2016-06-12 13:31 被阅读512次

    有的时候我们需要在一些特殊的情况下去修改iOS状态栏的背景颜色,去设置成我们想要的颜色。我们可以这么做

    OC:

     - (void)setStatusBarBackgroundColor:(UIColor *)color {
    
        UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    
        if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
            statusBar.backgroundColor = color;
        }
    }
    

    Swfit:

    func setStatusBarBackgroundColor(color: UIColor) {
    
        guard  let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView else {
            return
        }
    
        statusBar.backgroundColor = color
    }```

    相关文章

      网友评论

      • 奋斗的新手: :pensive:哈哈 对不住了 我引用错了可以用的,莫怪啊 。

      本文标题:手动更改iOS状态栏的颜色

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