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

时间:2016-09-19 22:59:20

标签: swift3 ios10

此技巧在iOS 10中不再有效:

    guard  let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView else {

15

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

我正在寻找一个迅捷的答案。感谢。

2 个答案:

答案 0 :(得分:11)

请尝试此代码......

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

答案 1 :(得分:1)

我可以在iOS 10 / Swift 3中通过添加彩色UIView来完成此操作  相同大小的状态栏。我将这些行放在FORM.FRX

 INSERT INTO USEROUT (CUSER, FILENAME)
 SELECT MOMUSER.CODE, 'FORM.FRX'
 FROM MOMUSER
 LEFT JOIN USEROUT ON MOMUSER.CODE = USEROUT.CUSER 
 WHERE USEROUT.CUSER IS NULL