2017-01-31 101 views
0

View controller-based status bar appearance設置爲YESInfo.plist文件。爲什麼我的狀態欄未改變首選風格?

視圖控制器,而不是在一個導航堆棧,經由模態SEGUE呈現。在這裏面,我對雨燕3/iOS的10以下屬性重寫:

override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } 

儘管如此,狀態欄將保留其缺省(暗)的造型。然而,當我打印preferredStatusBarStyleviewDidLoad,我得到的1一個rawValue。檢查出documentation1.lightContent

我試圖在狀態欄的樣式改變爲.lightContent,因爲該視圖包含UIVisualEffectViewdark一個UIBlurEffectStyle值。

我做錯了什麼嗎?

回答

-2

解決方法:

變化View controller-based status bar appearance爲NO

self.setStatusBarStyle(.lightContent) 
self.setNeedsStatusBarAppearanceUpdate() 
2

一下添加到模態呈現視圖控制器:

override var modalPresentationCapturesStatusBarAppearance: Bool { 
    return true 
} 
+0

我能解決我的問題與解決方案的一個小調整。看起來'modalPresentationCapturesStatusBarAppearance'不是可以重寫的屬性,因爲它是可變的。編譯錯誤在我的答案中提供。 –

2

與馬特的answer幫助下,我能解決我的問題。我不得不使用viewDidLoad如下:

modalPresentationCapturesStatusBarAppearance = true 

當我試圖馬特的解決方案,我收到兩條編譯錯誤:Cannot override mutable property with read-only property 'modalPresentationCapturesStatusBarAppearance'Getter for 'modalPresentationCapturesStatusBarAppearance' with Objective-C selector 'modalPresentationCapturesStatusBarAppearance' conflicts with getter for 'modalPresentationCapturesStatusBarAppearance' from superclass 'UIViewController' with the same Objective-C selector

0
  1. 轉到info.plist中,並設置UIViewControllerBasedStatusBarAppearance
  2. 轉到AppDelegate.swift然後轉到功能個didFinishLaunchingWithOptions,設置要如下的顏色:

    UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent

請讓我知道,如果它可以幫助你。 謝謝。

+0

我只需要一個視圖控制器來設置燈光狀態欄,因此爲整個應用程序設置它並不理想。但是,我找到了解決方案,這在我的答案中有所描述。 –

+0

謝謝,這對我很有幫助 – inzo

相關問題