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 上将状态栏的内容颜色设置为白色


- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01