Change Status Bar Background Color in Swift 3

前端 未结 14 1629
挽巷
挽巷 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 04:46

    For iOS 11 and Xcode 9 use the following steps.

    1. create an extention to UIApplication class:

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

    2. In your class or wherever you want to change the Status bar's background color:

      UIApplication.shared.statusBarView?.backgroundColor = .red

    3. For light content or dark content of status bar simply go to Info.plist and add the following value row with value NO.

    View controller-based status bar appearance

    1. Now just set the light content or whatever you need in the General Tab of your project's settings.

提交回复
热议问题