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

问题描述:

我正在设置导航栏和状态栏。当我从我的应用程序调用时更改状态栏的颜色

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

然后我加了th e下面的代码。保证:

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

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

    UIApplication.shared.statusBarView?.backgroundColor = .clear 

} 

扩展的UIApplication {VAR statusBarView:UIView的?返回值(forKey:“statusBar”)为? UIView的 }}

UIApplication.shared.statusBarView?.backgroundColor = .red