2017-08-08 78 views
0

我正在設置導航欄和狀態欄。當我從我的應用程序調用時更改狀態欄的顏色

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 

} 

回答

0

擴展的UIApplication {VAR statusBarView:UIView的?返回值(forKey:「statusBar」)爲? UIView的 }}

UIApplication.shared.statusBarView?.backgroundColor = .red

相關問題