Change the status bar color in iOS swift

 Solution:

extension UIViewController {

    func statusBarColorUpdate() {

        

        if #available(iOS 13.0, *) {

                let window = UIApplication.shared.windows.first


                let topPadding = window?.safeAreaInsets.top


                let statusBar = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: topPadding ?? 0.0))


                statusBar.backgroundColor = UIColor.red


                UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.addSubview(statusBar)


        } else {

            let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)

            statusBarView.backgroundColorUIColor.red // Set your desired color here

            view.addSubview(statusBarView)

            

            // Update the layout to account for the status bar

            view.layoutIfNeeded()


        }

    }

}


Add the above function as extension then call the function in viewwill appear inside the viewcontroller


    override func viewWillAppear(_ animated: Bool) {

        statusBarColorUpdate()

    }

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift