XCode 6-b3(Swift)中状态栏的彩色文本

XCode 6-b3(Swift)中状态栏的彩色文本,swift,xcode6,Swift,Xcode6,我试图修改状态栏的颜色文本,但没有人回答不起作用。 有专门针对XCode 6的吗 我试过插入: override func preferredStatusBarStyle() -> UIStatusBarStyle { return UIStatusBarStyle.LightContent } 至UIViewController 也 至AppDelegate.swift 我试着在info.plist 但这并不影响它。如何将状态栏颜色文本更改为白色?在Info.plist中,您需

我试图修改状态栏的颜色文本,但没有人回答不起作用。 有专门针对XCode 6的吗

我试过插入:

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

AppDelegate.swift
我试着在
info.plist

但这并不影响它。如何将状态栏颜色文本更改为白色?

在Info.plist中,您需要将基于控制器的状态栏外观定义为任何值

如果定义它YES,则应覆盖每个视图控制器中的
preferredStatusBarStyle
函数

如果定义它NO,则可以使用在
AppDelegate
中设置样式


UIApplication.sharedApplication().statusBarStyle=.LightContent

Keenle是正确的,从iOS7开始,您必须选择退出基于viewController的状态栏样式,然后才能在应用程序范围内进行设置

医生::

若要退出基于视图控制器的状态栏外观行为,必须将值为“否”的UIViewControllerBasedStatusBarAppearance键添加到应用程序的Info.plist文件中,但不建议这样做


确保将info.plist文件中的
查看基于控制器的状态栏外观
设置为

此外,如果您在UINavigationController中,则不能简单地在其中的ViewController中设置样式。为UINavigationController创建子类,并将其添加到其中:

override func preferredStatusBarStyle() -> UIStatusBarStyle {

    if let vc = self.viewControllers?.last as? UIViewController {
        return vc.preferredStatusBarStyle()
    }

    return super.preferredStatusBarStyle()
}
现在,您可以在UIViewController子类中设置条形图样式,UINavigationController将侦听它:)。

只需在plist中设置“基于视图控制器的状态条形图外观==NO”,并在didfinshLaunching方法中的appdelegate类中放置一行

 UIApplication.sharedApplication().statusBarStyle = .LightContent

Swift 3.0

只需将
查看基于控制器的状态栏外观==NO
设置到
*.plist
中,并在
返回之前的
didfishlaunchingwithoptions
方法中的appdelegate类的下面代码中

let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
    statusBar.backgroundColor = UIColor.red
}
UIApplication.shared.statusBarStyle = .lightContent

您可以根据您的要求更改
backgroundColor
statusBarStyle

我知道了!我只是在info.plist中没有“基于视图控制器的状态栏外观”。我手动添加并定义了它。谢谢。我尝试过很多方法,但是我无法让它改变UIStatusBar的颜色:(@JorgeVicenteMendoza,它总是透明的吗?总是暗的!我尝试过在info.plist中添加值,试图覆盖视图控制器中调用self.setNeedsStatusBarAppearanceUpdate()的函数(用于iOS7)但无法使其成为lightXcode 6,使用Swift:1.Info.plist,添加此属性:基于视图控制器的状态栏=NO 2。在AppDelegate.Swift中,在ApplicationIDFinishLaunching内部,添加以下行:UIApplication.sharedApplication().statusBarStyle=UIStatusBarStyle.LightContents这应该是注释,而不是答案!
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
    statusBar.backgroundColor = UIColor.red
}
UIApplication.shared.statusBarStyle = .lightContent