xcode 如何在 iOS7 上设置状态栏样式以点亮内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22544021/
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 style to light content on iOS7?
提问by Upvote
I tried several solutions from SO for this problem but none of them worked for me. I created a new iOS7 project with one simple view. I tried setting
我为这个问题尝试了 SO 的几种解决方案,但没有一个对我有用。我用一个简单的视图创建了一个新的 iOS7 项目。我试过设置
View controller-based status bar appearance to NO
and in AppDelegate:
并在 AppDelegate 中:
[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
However this removes the status bar completely.
但是,这会完全删除状态栏。
Without the View controller-based status bar appearance option, Regardless what I set for Status bar style in the plist file, the status bar text is still black. I need it to be white for the entire application. Is this possible?
如果没有基于视图控制器的状态栏外观选项,无论我在 plist 文件中为状态栏样式设置了什么,状态栏文本仍然是黑色的。我需要它在整个应用程序中都是白色的。这可能吗?
I am on latest xcode version.
我使用的是最新的 xcode 版本。
回答by Obj-Swift
did you try it without "Animated:No" ?
你在没有“Animated:No”的情况下尝试过吗?
Go to Info tab of the project target, Add Row:
转到项目目标的信息选项卡,添加行:
UIViewControllerBasedStatusBarAppearance, set value NO
UIViewControllerBasedStatusBarAppearance,设置值 NO
Then in appdelegate.m
然后在 appdelegate.m
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[application setStatusBarStyle:UIStatusBarStyleLightContent];
}
This should set it application wide.
这应该将其设置为广泛应用。
回答by smitt04
The Accepted answer seemed to work sometimes. I found out that the UIViewController can change the status bar style also. To get around this and always work, cause I didn't need the UIViewControllers controlling the status bar, I had to set UIViewControllerBasedStatusBarAppearance
to NO
in my Info.plist
接受的答案有时似乎有效。我发现 UIViewController 也可以更改状态栏样式。为了解决这个问题,总是工作,因为我并不需要UIViewControllers控制状态栏,我不得不设置UIViewControllerBasedStatusBarAppearance
到NO
我Info.plist
回答by Logan
Use needsStatusBarAppearanceUpdate
to update status bar in viewDidLoad:
method of view controller
用于needsStatusBarAppearanceUpdate
在viewDidLoad:
视图控制器的方法中更新状态栏
[self setNeedsStatusBarAppearanceUpdate];
Now add below method into view controller:
现在将以下方法添加到视图控制器中:
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
回答by Brian Sachetta
I would go with Logan's answer. As of iOS 9, UIApplication's setStatusBarStyle:
method is deprecated anyway, so you'll want to start moving away from using that. The preferred method, now is to implement preferredStatusBarStyle
within your ViewController
like Logan has described.
我会同意洛根的回答。从 iOS 9 开始,setStatusBarStyle:
无论如何都不推荐使用UIApplication 的方法,因此您将希望开始不再使用它。首选方法,现在是preferredStatusBarStyle
在您ViewController
像 Logan 所描述的那样实施。