我跟着这个线程来覆盖-preferredStatusBarStyle,但它没有被调用.我可以更改任何选项以启用它吗?(我在我的项目中使用XIB.)
在XCode 7.3.x中,我使用以下命令更改了StatusBar的背景颜色:
func setStatusBarBackgroundColor(color: UIColor) {
guard let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView else {
return
}
statusBar.backgroundColor = color
}
Run Code Online (Sandbox Code Playgroud)
但似乎这不再适用于Swift 3.0.
我尝试过:
func setStatusBarBackgroundColor(color: UIColor) {
guard let statusBar = (UIApplication.shared.value(forKey: "statusBarWindow") as AnyObject).value(forKey: "statusBar") as? UIView else {
return
}
statusBar.backgroundColor = color
}
Run Code Online (Sandbox Code Playgroud)
但它给了我:
this class is not key value coding-compliant for the key statusBar.
Run Code Online (Sandbox Code Playgroud)
任何想法如何使用XCode8/Swift 3.0进行更改?