Gally Gally - 1 year ago 100
iOS Question

Change foregroundcolor of statusbar

I used this code in swift 2.3 to change the foreground color of status bar:

(application.value(forKey: "statusBar") as AnyObject).setValue(UIColor.red, forKey: "foregroundColor")


But in the update to swift 3.0 this part not work because the statusbar no have the foreground key.

Someone has been able to change the color of statusbar in swift 3.0 ?

Thank you.

Answer Source

i solve my problem with this lines in the AppDelegate:

let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
statusBar.setValue(UIColor.red, forKey: "_foregroundColor")

Regards.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download