There is a simple area with the Navigation Bar at the top, and after it the stretched Table View.

Navigation Bar has painted some RGB color and now there is a need to paint the area above it in the same color - Status Bar.

In the file AppDelegate.swift in the application I added this line:

 UIApplication.shared.statusBarView?.backgroundColor = UIColor.init(red: CGFloat(7), green: CGFloat(14), blue: CGFloat(30), alpha: CGFloat(1)) 

And at the very bottom of the expanded UIApplication :

 extension UIApplication { var statusBarView: UIView? { return value(forKey: "statusBar") as? UIView } } 

Does not work. But if UIColor.init() replaced, for example, with .red , the Status Bar will turn red.

Why doesn't UIColor.init() and how can I set my RGB color in the Status Bar?

    1 answer 1

    It does not work, because (as reported by Xcode) "UIColor created with component values ​​far outside the expected range", i.e. the values ​​of the color components are outside the limits. The maximum possible value of a color component is 1.0. So you need to divide the value of each component by 255.0, like this:

     UIApplication.shared.statusBarView?.backgroundColor = UIColor.init(red: CGFloat(7 / 255.0), green: CGFloat(14 / 255.0), blue: CGFloat(30 / 255.0), alpha: CGFloat(1))