2013-10-04 44 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)时,也使用相同的代码