Swift Change statusBar backgoundColor和textColor

时间:2016-08-10 04:35:25

标签: background-color statusbar textcolor

解答:

I / Open Info.plist文件 - >添加新行:查看基于控制器的状态栏外观 - >设置为[是]

enter image description here

II /打开yourViewController.swift文件并插入:

override func prefersStatusBarHidden() -> Bool {
    // Return false -> Show statusBar
    return false
}

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    // Change status background color
    let statusBar: UIView = UIApplication.sharedApplication().valueForKey("statusBar") as! UIView
    if statusBar.respondsToSelector(Selector("setBackgroundColor:")) {
        statusBar.backgroundColor = UIColor.redColor()
    }
    // Change textColor -> While(LightContent)
    return UIStatusBarStyle.LightContent
}

0 个答案:

没有答案