Change Status Bar Background Color in Swift 3

前端 未结 14 1630
挽巷
挽巷 2020-11-28 04:21

In XCode 7.3.x ill changed the background Color for my StatusBar with:

func setStatusBarBackgroundColor(color: UIColor) {
guard  let statusBar = UIApplicatio         


        
14条回答
  •  一个人的身影
    2020-11-28 05:00

    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)

提交回复
热议问题