将其放入您的 AppDelegate 应用程序中:didFinishLaunchingWithOptions:
斯威夫特 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")
}
斯威夫特 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")
}
斯威夫特2.0:
application.valueForKey("_statusBar")?.setValue(UIColor.redColor(), forKey: "_foregroundColor")
Objective-C:
[[application valueForKey:@"_statusBar"] setValue: [UIColor redColor] forKey: @"_foregroundColor"];
很难说你的应用程序是否会被应用程序商店拒绝。使用KVC访问_statusBar
财产不会让您的应用程序被拒绝,因为UIApplication
类本身并不隐藏。
话虽如此,也不是UIStatusBar
隐藏类,即。它不在 SDK 中私有框架目录也没有标记为__attribute__((visibility("hidden")))
类名也不以下划线开头。
如果您的应用程序因使用此功能而被拒绝,请在下面发表评论,以便我更新答案。