从我的应用程序调用时更改状态栏的颜色

时间:2017-08-08 08:27:40

标签: ios swift

我正在设置导航栏和状态栏。

static func setParamsBars(){
    let bounds = UIScreen.main.bounds

    UIApplication.shared.statusBarView?.backgroundColor = .clear

    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white, NSFontAttributeName: UIFont(name: "SFUIDisplay-Regular", size: 18)!]

    let imagebar : UIImage = UIImage(color: UIColor(red: 136.0/255.0, green: 136.0/255.0, blue: 136.0/255.0, alpha: 0.8), size: CGSize(width: bounds.size.width, height: 84))!
    UINavigationBar.appearance().setBackgroundImage(imagebar, for: .default)
    UINavigationBar.appearance().shadowImage = UIImage()
    UINavigationBar.appearance().isTranslucent = true
}

并在didFinishLaunchingWithOptions

中调用此函数

我的第一个屏幕enter image description here

我拨电话号码enter image description here

然后当我返回应用程序时,状态栏会改变颜色 enter image description here

然后我添加了以下代码。确保:

func applicationDidBecomeActive(_ application: UIApplication) {
    AppEventsLogger.activate(application)

    print("applicationDidBecomeActive")
    //AppDelegate.setParamsBars()
    //UINavigationBar.appearance().clipsToBounds = false
    //UINavigationBar.appearance().isTranslucent = true

    UIApplication.shared.statusBarView?.backgroundColor = .clear

}

1 个答案:

答案 0 :(得分:0)

扩展名UIApplication {     var statusBarView:UIView? {         返回值(forKey:" statusBar")为?的UIView     } }

UIApplication.shared.statusBarView?.backgroundColor = .red