如何设置状态栏背景颜色 iOS 7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19176784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set Status bar background color iOS 7
提问by SWT
iOS 6 look...
iOS 6 外观...
Same way i would like to display status bar in iOS 7 like
我想以同样的方式在 iOS 7 中显示状态栏,例如
see this
看到这个
but My actual output (Overlap)
但我的实际输出(重叠)
i have tried following logic
我试过以下逻辑
open your info.plist and set "View controller-based status bar appearance" = NO
it's not working in my code,,,
它在我的代码中不起作用,,,
回答by Stanislav
You have to do 2 things. First is to open your info.plist
and set "View controller-based status bar appearance" = NO
你必须做两件事。首先是打开你的info.plist
并设置"View controller-based status bar appearance" = NO
And the second is to add this lines to application:didFinishLaunchingWithOptions
第二个是将此行添加到 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);
}
}
回答by Eric Sanchez
Read this article: http://www.appcoda.com/customize-navigation-status-bar-ios-7/
阅读这篇文章: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)];
回答by Bhumit Mehta
Move your frame 20 pixels down. You can try writing this in your ViewWillappear or DidAppear
将框架向下移动 20 像素。您可以尝试在 ViewWillappear 或 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;
Now set background color of window to black in applicationDidFinishLaunching and set statusbar font to be white (StatusBarContentLight)
现在在 applicationDidFinishLaunching 中将窗口的背景颜色设置为黑色并将状态栏字体设置为白色 (StatusBarContentLight)
Remember what i am suggesting is not perfect solution but a fix that will work nicely. Also use same code when app changes its orientation (ShouldAutorotate)
记住我的建议不是完美的解决方案,而是一个可以很好地工作的修复。当应用程序更改其方向时也使用相同的代码(ShouldAutorotate)