通过iOS 7更改状态栏背景颜色 [英] Change the status bar background color color past iOS 7
问题描述
我想在iOS 7上更改状态栏的背景颜色,我正在使用此代码:
I want to change background color of status bar on iOS 7, and I'm using this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[UIApplication sharedApplication].statusBarHidden = NO;
self.window.clipsToBounds = YES;
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
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);
...
...
}
当我写这个时,它会显示黑色背景的状态栏;我希望它有红色背景。
When I write this it shows the status bar with a black background; I want it to have a red background.
如何将状态栏的颜色更改为红色背景而不是黑色?
How can change the color of the status bar to have a red background instead of black?
推荐答案
在iOS 7及更高版本中,状态栏为透明。将视图的 backgroundColor
设置为状态栏所需的颜色。
In iOS 7 and later, the status bar is transparent. Set the backgroundColor
of your view to the color you want for the status bar.
或者,您可以添加视图顶部有20px高的红色子视图。
Or, you can add a 20px-high subview with red color at the top of your view.
请参阅 Apple Transition Guide 更多信息。
另外,请确保您的 preferredStatusBarStyle
是 UIStatusBarStyleLightContent
。并在您的Info.plist中将查看基于控制器的状态栏外观设置为否。
Also, make sure that your preferredStatusBarStyle
is UIStatusBarStyleLightContent
. and in your Info.plist set "View controller-based status bar appearance" to "NO".
这篇关于通过iOS 7更改状态栏背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!