如何在iOS中更改状态栏文本颜色 [英] How to change Status Bar text color in iOS

查看:99
本文介绍了如何在iOS中更改状态栏文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序背景较暗,但在iOS 7中状态栏变得透明。所以我看不到任何东西,只有角落里的绿色电池指示灯。如何将状态栏文本颜色更改为白色,就像在主屏幕上一样?

My application has a dark background, but in iOS 7 the status bar became transparent. So I can't see anything there, only the green battery indicator in the corner. How can I change the status bar text color to white like it is on the home screen?

推荐答案


  1. 在.plist文件中将 UIViewControllerBasedStatusBarAppearance 设置为 YES

viewDidLoad 中执行 [self setNeedsStatusBarAppearanceUpdate];

添加以下方法:

- (UIStatusBarStyle)preferredStatusBarStyle
{ 
    return UIStatusBarStyleLightContent; 
}


注意:这不适用于 UINavigationController 内的控制器,请参阅 Tyson的评论如下 :)

Note: This does not work for controllers inside UINavigationController, please see Tyson's comment below :)

Swift 3 - 这将在 UINavigationController 中使用控制器。在控制器中添加此代码。

Swift 3 - This will work controllers inside UINavigationController. Add this code inside your controller.

// Preferred status bar style lightContent to use on dark background.
// Swift 3
override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

这篇关于如何在iOS中更改状态栏文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆