How to set status bar#39;s content color to white on iOS 7(如何在 iOS 7 上将状态栏的内容颜色设置为白色)
问题描述
我的应用程序的背景颜色是黑色.由于 iOS 7 上整个视图都在状态栏下方,因此很难区分状态栏上的内容.那么如何将状态栏的内容颜色改为白色呢?
My App’s background colour is black. Cause the whole view is below the status bar on iOS 7, the content on the status bar will hard to be distinguished. So how to change status bar’s content colour to white?
我尝试了 preferredStatusBarStyle
和其他几种方法,但都失败了.
I've tried preferredStatusBarStyle
and several other ways, but failed.
推荐答案
- 在您的 info.list 文件中将查看基于控制器的状态栏外观"设置为 NO;
插入
- Set "View controller-based status bar appearance" to NO in your info.list file;
Insert
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
到 AppDelegate.m 的 -application:didFinishLaunchingWithOptions:
.
to -application:didFinishLaunchingWithOptions:
of the AppDelegate.m.
<小时>
注意:UIStatusBarStyleDefault
是状态栏样式的默认值,它会显示黑色内容.UIStatusBarStyleBlackTranslucent
&UIStatusBarStyleBlackOpaque
在 iOS 7.0 中已弃用.
Note: UIStatusBarStyleDefault
is the default value for the status bar style, it'll show black content instead. Both UIStatusBarStyleBlackTranslucent
& UIStatusBarStyleBlackOpaque
are deprecated in iOS 7.0.
作为 @ZakariaDarwish 提到,-setStatusBarStyle
方法在 iOS 9 中已被弃用.(注:原问题是很久以前针对 iOS 7 提出的,我不支持现在,下面的新解决方案适用于我在 iOS 9 下,因此在此处更新.)
As @ZakariaDarwish mentioned, the method -setStatusBarStyle
is deprecated in iOS 9. (Note: The original question was asked for iOS 7 long time ago, and I don't support it now, the new solution below works for me under iOS 9, hence update here.)
所以,剩下的唯一方法(至少现在)是在您的视图控制器中实现 -preferredStatusBarStyle
(记得设置基于视图控制器的状态栏外观" 返回是).
So, the only way left (at least for now) is to implement -preferredStatusBarStyle
in your view controller (remember to set "View controller-based status bar appearance" back to YES).
一旦 -preferredStatusBarStyle
或 -prefersStatusBarHidden
中的值发生更改,您可以调用 UIViewController 的实例方法 -setNeedsStatusBarAppearanceUpdate
.
You can invoke UIViewController's instance method -setNeedsStatusBarAppearanceUpdate
once value changed in -preferredStatusBarStyle
or -prefersStatusBarHidden
.
还有两种方法-childViewControllerForStatusBarStyle
&-childViewControllerForStatusBarHidden
根据需要从子视图控制器返回首选样式.
There're also two methods -childViewControllerForStatusBarStyle
& -childViewControllerForStatusBarHidden
to return the preferred style from child view controller as you want.
例如,如果您使用以下方法
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
要切换之前的状态栏样式,可以使用下面的代码示例
to switch status bar style before, you can use code sample below
- (void)shouldChangeStatusBarStyleToLightContent:(BOOL)toLightContent
animated:(BOOL)animated
{
_shouldChangeStatusBarStyleToLightContent = toLightContent;
if (animated) {
[UIView animateWithDuration:.3f animations:^{ [self setNeedsStatusBarAppearanceUpdate]; }];
} else {
[self setNeedsStatusBarAppearanceUpdate];
}
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return (_shouldChangeStatusBarStyleToLightContent ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault);
}
现在为这个更新的解决方案.
for this updated solution now.
这篇关于如何在 iOS 7 上将状态栏的内容颜色设置为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS 7 上将状态栏的内容颜色设置为白色
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01