4 MINDS

Sistema para Gestão de Conhecimento

IOS 13 + status bar color





    



static func setStatusBarBackgroundColor(_ rootViewController: UIViewController) {

        

let colorOrange = UIColor.init(red: 242/255.0, green: 101/255.0, blue: 34/255.0, alpha: 1.0)

        let statusBar = getStatusBarView()

        statusBar.backgroundColor = colorOrange

        

        UIApplication.shared.setStatusBarStyle(.lightContent, animated: true)

    }

    

    static func getStatusBarView() -> UIView{

        

        let statusBarViewTag: NSInteger = 38482458385

        

        if #available(iOS 13, *) {

            if UIApplication.shared.keyWindow != nil &&

                UIApplication.shared.keyWindow!.viewWithTag(statusBarViewTag) != nil {

                return UIApplication.shared.keyWindow!.viewWithTag(statusBarViewTag)!

            }else {

                let statusBarFrame = UIApplication.shared.keyWindow!.windowScene!.statusBarManager!.statusBarFrame

                let statusBar: UIView = UIView.init(frame: statusBarFrame)

                statusBar.tag = statusBarViewTag;

                UIApplication.shared.keyWindow!.addSubview(statusBar)

                return statusBar

            }

       }

       else {

            return UIApplication.shared.value(forKey: "statusBar") as! UIView

       }

    }


In delegate call 


setStatusBarBackgroundColor(rootViewController)