xcode 如何更改 UIStatus 栏颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3762013/
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 change the UIStatus bar color?
提问by jeevangs
I am trying to change the status bar color to Black translucent. I have changed my Info.plist UIStatusBarStyle UIStatusBarStyleBlackTranslucent
我正在尝试将状态栏颜色更改为黑色半透明。我已经改变了我的 Info.plist UIStatusBarStyle UIStatusBarStyleBlackTranslucent
And I have added these lines of code also to applicationDidFinishLaunching:()
我也将这些代码行添加到 applicationDidFinishLaunching:()
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent 动画:NO];
After doing these changes, my status bar changes to black translucent, till my splash screen appears. Once, my application is loaded fully and when the contents are displayed, it is again back to the default gray color.Can anyone please tell me where I am going wrong or where i should change?
完成这些更改后,我的状态栏变为黑色半透明,直到出现闪屏。有一次,我的应用程序完全加载,当显示内容时,它又恢复为默认的灰色。谁能告诉我哪里出错了或者我应该在哪里更改?
Thanks in advance.
提前致谢。
回答by dineth
Right click on your info.plist and "Add Row". From there you can select what you want to add. There is a value called "Status bar style". Pick that. The corresponding value can also be pulled down and you can pick from gray, black with alpha .5, black.
右键单击您的 info.plist 和“添加行”。从那里您可以选择要添加的内容。有一个值称为“状态栏样式”。选那个。也可以下拉相应的值,您可以从带有 alpha 0.5 的灰色、黑色、黑色中进行选择。
Save, reload your app. That's all I had to do.
保存,重新加载您的应用程序。这就是我所要做的。
(I know the qn is 1 month old but I thought I'd leave the answer here anyway in case ppl search for it).
(我知道 qn 已经 1 个月大了,但我想无论如何我都会把答案留在这里,以防万一ppl 搜索它)。
回答by chadbag
I had a similar issue (2 tabs out of 5 in a root UITabBarController had gray looking status bar). When I went and un-checked "Clip Subviews" for the main view of the controller for the tab that had the gray looking status bar, it "fixed" the problem as I was able to set my main background image to have a -20 "y" value so that the translucent status bar had something to be "translucent" over.
我有一个类似的问题(根 UITabBarController 中的 5 个标签中有 2 个有灰色的状态栏)。当我去取消选中控制器主视图的“剪辑子视图”时,该选项卡具有灰色的状态栏,它“解决了”问题,因为我能够将主背景图像设置为 -20 “y”值,以便半透明状态栏有一些东西可以“半透明”。
EDIT:
编辑:
Turns out that what I really wanted to do was to set the "Wants Full Screen" option in IB (and/or wantsFullScreenLayout
property in the VC for programmatically created VC) instead of turning off clipping and doing a negative offset. This allowed me to see that I really did have a translucent status bar but had had layout problems so nothing was underneath it.
事实证明,我真正想做的是在 IB 中设置“想要全屏”选项(和/或wantsFullScreenLayout
VC 中以编程方式创建的 VC 的属性),而不是关闭剪辑并进行负偏移。这让我看到我确实有一个半透明的状态栏,但有布局问题,所以它下面没有任何东西。
So if it appears that you have an other than black translucent status bar when you think you should have one, make sure that your views do layout underneath the status bar and it is not a visual effect that looks gray or black but in reality is just the lack of something to show through.
因此,如果您认为应该拥有一个非黑色半透明状态栏,请确保您的视图在状态栏下方进行布局,并且它不是看起来灰色或黑色的视觉效果,但实际上只是缺乏可以表现出来的东西。
回答by bosmacs
You'll want to set the UIStatusBarStyle
key (also diplayed as "status bar style") in your app's Info.plist to UIStatusBarStyleBlackTranslucent
.
您需要将UIStatusBarStyle
应用程序的 Info.plist 中的键(也显示为“状态栏样式”)设置为UIStatusBarStyleBlackTranslucent
。