In XCode 7.3.x ill changed the background Color for my StatusBar with:
func setStatusBarBackgroundColor(color: UIColor) {
guard let statusBar = UIApplicatio
I made this extension to change color of status bar. It's not dependent on the key. So it is much safer to use
public extension UIViewController {
func setStatusBar(color: UIColor) {
let tag = 12321
if let taggedView = self.view.viewWithTag(tag){
taggedView.removeFromSuperview()
}
let overView = UIView()
overView.frame = UIApplication.shared.statusBarFrame
overView.backgroundColor = color
overView.tag = tag
self.view.addSubview(overView)
}
}
Here is usage anywhere in viewcontroller:
setStatusBar(color: .red)
Add following code in your extension file to edit your status bar in swift 4 and Above:
extension UIApplication {
var statusBarView: UIView? {
if responds(to: Selector(("statusBar"))) {
return value(forKey: "statusBar") as? UIView
}
return nil
}
}
now, we can edit status bar by adding following line in our ViewController class:
UIApplication.shared.statusBarView?.backgroundColor = <Your Color name>
ex: UIApplication.shared.statusBarView?.backgroundColor = .red
Hope, this will be helpful. Thanks