自定义iOS 7状态栏文本颜色

时间:2014-07-31 08:10:20

标签: ios ios7 ios6

我想知道除了黑色白色颜色之外是否还有办法更改iOS 7状态栏文字颜色?

2 个答案:

答案 0 :(得分:6)

将它放在你的AppDelegate应用程序中:didFinishLaunchingWithOptions:

Swift 4.2:

if UIApplication.shared.responds(to: Selector(("statusBar"))),
    let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView,
    statusBar.responds(to: #selector(getter: CATextLayer.foregroundColor)) {
    statusBar.setValue(UIColor.red, forKey: "foregroundColor")
}

Swift 3.0:

如果Apple决定更改类的命名(极不可能),我们将添加一些类型安全。

if application.responds(to: Selector(("statusBar"))),
   let statusBar = application.value(forKey: "statusBar") as? UIView,
   statusBar.responds(to: Selector(("foregroundColor"))) {
   statusBar.setValue(UIColor.red, forKey: "foregroundColor")
}

Swift 2.0:

application.valueForKey("_statusBar")?.setValue(UIColor.redColor(), forKey: "_foregroundColor")

<强>目标-C:

[[application valueForKey:@"_statusBar"] setValue: [UIColor redColor] forKey: @"_foregroundColor"];

很难说您的应用是否会被应用商店拒之门外。使用KVC访问_statusBar属性不会导致您的应用被拒绝,因为UIApplication类本身未被隐藏。

话虽如此,UIStatusBar类也没有隐藏,即。它不在SDK的 PrivateFrameworks 目录中,也没有标记为__attribute__((visibility("hidden"))),类名也不以下划线开头。

如果您的应用因使用此功能而被拒绝,请在下面发表评论,以便我可以更新答案。

答案 1 :(得分:1)

理论上这是可能的。您需要在iOS上阅读有关私人API的信息。这是从UIStatusBar例子开始的好地方:

http://b2cloud.com.au/tutorial/using-private-ios-apis/

请记住,如果您使用私人API,可能无法在Appstore上提交您的应用。