2015-04-22 23 views
1

我收到了一個「舊項目」,並對其進行了修改以支持iOS8。 在應用程序狀態欄中有黑色。保留傳統項目中的黑色狀態欄

我將View controller-based status bar appearance設置爲NO,並將狀態欄樣式設置爲Info.plist中的黑色不透明樣式。

這裏是AppDelegate.m文件的一部分:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { 
     application.statusBarStyle = UIStatusBarStyleLightContent; 
    } 

    application.statusBarHidden = NO; 

    UIImage *navBarImage = [[UIImage imageNamed:@"navigation-bar"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 9, 0, 9)]; 

    [[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault]; 

所以我預計將會對所有控制器,與白色黑色的狀態欄。

它適用於大多數情況。但是當我推新的VC時,隱藏的導航欄會改變顏色,並且在導航欄啓用時工作正常。

一個錯誤的結果:(當self.navigationController.navigationBarHidden = YES;

Wrong results, status bar translucent and has white color

這是我得到的,而不是隱藏的導航欄:

Correct results,but with navigation bar visible, status bar has black color

我不知道爲什麼竟然,導航欄的存在會影響狀態欄的顏色(風格)。

如何使用隱藏的導航欄顯示VC(推入導航堆棧)時在iOS7(8)上使狀態欄變黑?

回答

1

創建一個視圖,將其放置在狀態欄所在的位置,並將其背景顏色設置爲您需要的顏色。例如:

UIView *statusBarView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 
         [UIApplication sharedApplication].statusBarFrame.size.width, 
         [UIApplication sharedApplication].statusBarFrame.size.height)]; 
statusBarView.backgroundColor = [UIColor blackColor]; // Set color 
[self.view addSubview:statusBarView]; 
+1

thx丹尼爾,確實,增加了半透明的觀點解決了,我的問題。但是,不要硬編碼大小,而應參考狀態欄屬性。 – siarheibrazil

相關問題