iosswiftxcodestatusbaruistatusbar

Changing the Color of the Status Bar


I am trying to change the color of the status bar to like a blue, or some other color.

Is this possible, or does Apple not allow it?


Solution

  • NOTE: This solution fails under iOS 13 and later.

    First in Plist set View controller-based status bar appearance to NO

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
    
        let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
        if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
            statusBar.backgroundColor = UIColor.blue
        }
        UIApplication.shared.statusBarStyle = .lightContent
    
        return true
    }
    

    The output screenshot is below

    enter image description here