2015-10-13 98 views
1

我在iOS應用程序中實現了一個導航欄,我將淺色設置爲白色,但是在運行應用程序時,狀態欄不遵循淺色,並且只是透明(請參閱圖片)。我的目標是讓狀態欄具有半透明的風格。無法更改狀態欄的樣式

如何解決這個問題?

enter image description here

+0

[更改狀態欄樣式IOS 7?(可能的重複http://stackoverflow.com/questions/19447137/ changing-status-bar-style-ios-7) –

回答

4

要更改狀態欄顏色在所有Viewcontrollers,添加到您的info.plist

<key>UIStatusBarStyle</key> 
<string>UIStatusBarStyleLightContent</string> 
<key>UIViewControllerBasedStatusBarAppearance</key> 
<false/> 

那麼幹淨,運行生成。

有關設置狀態欄的顏色特定ViewControllers添加在info.plist中

<key>UIViewControllerBasedStatusBarAppearance</key> 
<true/> 

而且在視圖控制器的viewDidLoad方法調用此方法如下:

[self setNeedsStatusBarAppearanceUpdate]; 

而且添加以下方法在ViewController中:

- (UIStatusBarStyle)preferredStatusBarStyle 
{ 
    return UIStatusBarStyleLightContent; 
} 

乾杯:]

+0

它只是將狀態欄的文本設置爲白色。它仍然是透明的 –

+0

參考此:http://stackoverflow.com/questions/19063365/how-to-change-the-status-bar-background-color-and-text-color-on-ios-7 –

+0

有多個答案,只需要通過。讓我知道它是否有幫助。 :) –

2

你已經試過了嗎?

UIApplication.sharedApplication().statusBarStyle = .LightContent 
2

試試這個

[self setNeedsStatusBarAppearanceUpdate];//add it in view didload 

- (UIStatusBarStyle) preferredStatusBarStyle { 
     return UIStatusBarStyleLightContent; 
    } 

檢查鏈接下一add the view in status bar 檢查 link