如何在IOS 10中设置状态返回背景颜色?

1 swift3 ios10

这个技巧在iOS 10中不再适用:

    guard  let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView else {
Run Code Online (Sandbox Code Playgroud)

15

"statusBarWindow"有效,但不是"statusBar".***由于未捕获的异常'NSUnknownKeyException'终止应用程序,原因:'[<_SwiftValue 0x60800049a9a0> valueForUndefinedKey:]:此类不是键值statusBar的键值编码兼容.

我正在寻找一个迅速的3回答.谢谢.

Saj*_*osh 11

请试试这个代码......

   let statWindow = UIApplication.shared.value(forKey:"statusBarWindow") as! UIView
   let statusBar = statWindow.subviews[0] as UIView
    statusBar.backgroundColor = UIColor.red //your required color
Run Code Online (Sandbox Code Playgroud)