2014-11-06 84 views
1

狀態欄我對狀態欄行爲黑色在iOS8上

我不需要透明的狀態欄 我需要它固定的和黑色有點困惑。 同樣喜歡iOS6的

我嘗試了很多, 我得到它, 其呈現黑色,只有當我啓動應用程序第一次, 當我的設備旋轉爲橫向,並再次作出人像,然後花費的導航欄顏色。

我在做什麼錯。

任何人都可以引導我。

這是我得到

enter image description here

這是我多麼希望

enter image description here

+2

您不能這樣做。想要做同樣的事情,那麼你必須在背景顏色爲(0,0,width,20)的同一幀上添加視圖,並且設置'View controller-status bar appearance = NO'和'[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];' – 2014-11-06 09:28:14

回答

0

這是iOS8,Swift,Xcode 6.3的解決方案。

添加背景顏色:

var statusBarBackground = UIView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 30)) 
statusBarBackground.backgroundColor = UIColor.blackColor() 
statusBarBackground.tag = 13 

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 
appDelegate.window!.rootViewController!.view.addSubview(statusBarBackground) 
appDelegate.window!.rootViewController!.view.bringSubviewToFront(navigationController!.navigationBar) 

移除背景顏色:

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 
for sv in appDelegate.window!.rootViewController!.view.subviews { 
    if sv.tag == 13 { 
     sv.removeFromSuperview() 
    } 
} 

我爲什麼不只是添加statusBarBackground到ViewController的看法?因爲我需要這個用於UIDocumentInteractionController預覽視圖,它現在不允許任何自定義。

爲什麼我讓statusBarBackground 30爲高,因此迫使我爲navigationBar做一個bringSubviewToFront?因爲我的導航欄有圓角(帶有蒙版圖層,所以不是圖像),因此顯示導航欄後面的視圖(我希望與狀態欄背景的顏色相同)

還需弄清楚:如果您點按預覽導航欄向上移動,但是(當然)statusVarBackground仍然存在,沒有任何代表告訴我預覽,如果您有任何想法,請將其留在註釋中。

1

您CAD做一個黑客設置狀態欄的顏色,應用程序難道不被蘋果拒絕,但不能保證Apple在下一個iOS版本中不會改變這種行爲。

- (void)setStatusBarColor:(UIColor *)color { 
id statusBarWindow = [[UIApplication sharedApplication] valueForKey:@"_statusBarWindow"]; 
NSString *statusBarWindowClassString = NSStringFromClass([statusBarWindow class]); 

if ([statusBarWindowClassString isEqualToString:@"UIStatusBarWindow"]) { 
    NSArray *statusBarWindowSubviews = [statusBarWindow subviews]; 

    for (UIView *statusBarWindowSubview in statusBarWindowSubviews) { 
     NSString *statusBarWindowSubviewClassString = NSStringFromClass([statusBarWindowSubview class]); 

     if ([statusBarWindowSubviewClassString isEqualToString:@"UIStatusBar"]) { 
      [statusBarWindowSubview setBackgroundColor:color]; 
     } 
    } 
} 
} 
+0

謝謝 它適用於我 讓我們來看看蘋果的行爲.... – Sagar 2014-11-06 10:09:51