我的应用程序背景是黑色的,但在iOS 7中,状态栏变成了透明的。所以我什么也看不见,只有角落里的绿色电池指示灯。如何将状态栏文本颜色改为白色,就像在主屏幕上一样?
当前回答
如果你有一个通过Interface Builder创建的嵌入式导航控制器,请确保在管理导航控制器的类中设置以下内容:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
这应该就是你所需要的。
其他回答
我做了一些不同的事情,这对我很有效。
在没有更改代码的情况下,我像这样配置了.plist文件:
基于控制器的状态栏外观>否 状态栏样式> UIStatusBarStyleLightContent(简单字符串)
我希望这能有所帮助。
edit
对于每个视图控制器,我改变“状态栏”的模拟度量属性,在故事板中,从“推断”到“轻内容”
这招对我很管用:
在plist中设置UIViewControllerBasedStatusBarAppearance为YES rootViewController需要方法实现 ——(UIStatusBarStyle) preferredStatusBarStyle
因为我的rootViewController是由Cocoapods (JASidePanelController)管理的,我通过一个类别添加了这个方法:
#import "JASidePanelController+StatusBarStyle.h"
@implementation JASidePanelController (StatusBarStyle)
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
@end
对我来说,什么都没用。我试图改变状态栏颜色在ViewController2,这是嵌入在NavigationController,这反过来,从ViewController1被模态地呈现。这种方法行不通:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .darkContent
}
什么都没有发生,直到我找到了这个解决方案: 将这一行添加到ViewController1
导航控制器。modalPresentationCapturesStatusBarAppearance = 真正的
let navigationController = UINavigationController(rootViewController: viewController2)
navigationController.modalPresentationStyle = .overFullScreen
navigationController.modalTransitionStyle = .crossDissolve
navigationController.modalPresentationCapturesStatusBarAppearance = true
self.present(navigationController, animated: true)
所以如果你的导航方案类似于ViewController1呈现的ViewController2,尝试modalPresentationCapturesStatusBarAppearance属性呈现的一个
文档:
The default value of this property is false. When you present a view controller by calling the present(_:animated:completion:) method, status bar appearance control is transferred from the presenting to the presented view controller only if the presented controller's modalPresentationStyle value is UIModalPresentationStyle.fullScreen. By setting this property to true, you specify the presented view controller controls status bar appearance, even though presented non-fullscreen. The system ignores this property’s value for a view controller presented fullscreen.
你不需要为此做任何代码
你需要在信息中添加“基于控制器的状态栏外观”键。请填写如下:
并将其值类型设置为布尔值,值设置为NO。 然后单击项目设置,然后单击“常规”选项卡并在“部署信息”下将首选状态栏样式设置为。light,如下所示:
这是它。
不需要做一些额外的,只是写这段代码在你的viewController和获得状态栏颜色白色
- (UIStatusBarStyle)preferredStatusBarStyle{return UIStatusBarStyleLightContent;}
推荐文章
- 如何删除默认的导航栏空间在SwiftUI导航视图
- Ios模拟器:如何关闭应用程序
- 如何在iOS中使用Swift编程segue
- Swift -整数转换为小时/分钟/秒
- 如何舍入一个双到最近的Int在迅速?
- 扁平化数组的数组在Swift
- Swift:声明一个空字典
- 在成功提交我的应用程序后,“太多符号文件”
- 从数组中随机选择一个元素
- 首先添加一个UIView,甚至是导航栏
- 我如何改变UIButton标题颜色?
- 在Swift中如何调用GCD主线程上的参数方法?
- NSLayoutConstraints是可动画的吗?
- iOS -构建失败,CocoaPods无法找到头文件
- CFNetwork SSLHandshake iOS 9失败