我的应用程序背景是黑色的,但在iOS 7中,状态栏变成了透明的。所以我什么也看不见,只有角落里的绿色电池指示灯。如何将状态栏文本颜色改为白色,就像在主屏幕上一样?


当前回答

转到项目->目标, 然后设置“状态栏样式”为“亮”。它使状态栏从启动屏幕变成白色。 然后在Info.plist中将“基于视图控制器的状态栏外观”设置为“NO”。

其他回答

在Plist中添加以下内容:

状态栏样式:UIStatusBarStyleLightContent 基于视图控制器的状态栏外观:NO

我在一个Swift项目中使用Xcode 6 beta 5,用于iOS 7应用程序。

以下是我所做的,而且很有效:

info.plist:

在AppDelegate。M,添加以下内容。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

} 

在Plist文件中,将“基于视图控制器的状态栏外观”设置为NO。

如果我使用UINavigationController,我在iOS 9和Swift 2.0中做这个

self.navigationController?.navigationBar.barStyle = UIBarStyle.Black

如果我使用模态segue

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return .LightContent
}

对我来说,什么都没用。我试图改变状态栏颜色在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.