2013-10-04 48 views
5

iOS 6的樣子......如何設置狀態欄背景色的iOS 7

enter image description here

同樣我也想在iOS的7顯示狀態欄像

看到這個

我的實際輸出(重疊)

我曾嘗試下面的邏輯

open your info.plist and set "View controller-based status bar appearance" = NO 

它不是在我的代碼工作,,,

+0

@ swt-他們有很多關於SO的問題,你有沒有搜索過 –

回答

17

你必須做兩件事情。首先是打開你的info.plist並設置"View controller-based status bar appearance" = NO

而第二個是這行添加到application:didFinishLaunchingWithOptions

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) 
{ 
    self.window.clipsToBounds = YES; 
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];  

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
    if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
    { 
     self.window.frame = CGRectMake(20, 0,self.window.frame.size.width-20,self.window.frame.size.height); 
     self.window.bounds = CGRectMake(20, 0, self.window.frame.size.width, self.window.frame.size.height); 
    } else 
    { 
     self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20); 
     self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height); 
    } 
} 
+0

我的應用程序以橫向模式運行。但是您的代碼顯示爲黑色條形右側和左側 – SWT

+0

已更新答案以支持兩種方向。 – Stanislav

+0

但工作正常......但是當我旋轉屏幕不會改變基於屏幕方向 – SWT

9

閱讀這篇文章:http://www.appcoda.com/customize-navigation-status-bar-ios-7/

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] 

[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)]; 
+0

這些開發人員將圖像放在他們的UINavigationBar上的優秀鏈接。 – capikaw

+1

可悲的是,我的iPad應用程序沒有做太多的工作。良好的鏈接,雖然 – cynistersix

+0

出於某種原因,這不適合我,storyboard,ios7。將該行添加到AppDelegate didFinishLaunching – Fraggle

0

20個像素向下移動你的框架。您可以在viewWillAppear中嘗試寫這樣或窗口到黑色的applicationDidFinishLaunching的DidAppear

CGRect frame = self.view.frame; 
frame.origin.y = 20; 

if (self.view.frame.size.height == 1024 || self.view.frame.size.height == 768) 
{ 
    frame.size.height -= 20; 
} 
self.view.frame = frame; 

現在設置背景顏色和設置狀態欄字體爲白色(StatusBarContentLight)

記住我的建議是不完美的解決方案但一個修復,將很好地工作。當應用程序改變其方向(ShouldAutorotate)時,也使用相同的代碼