把它放在你的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")
}
Run Code Online (Sandbox Code Playgroud)
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")
}
Run Code Online (Sandbox Code Playgroud)
Swift 2.0:
application.valueForKey("_statusBar")?.setValue(UIColor.redColor(), forKey: "_foregroundColor")
Run Code Online (Sandbox Code Playgroud)
Objective-C的:
[[application valueForKey:@"_statusBar"] setValue: [UIColor redColor] forKey: @"_foregroundColor"];
Run Code Online (Sandbox Code Playgroud)
很难说你的应用是否会被应用商店拒绝.使用KVC访问该_statusBar属性不会导致您的应用被拒绝,因为UIApplication该类本身未被隐藏.
话虽如此,UIStatusBar隐藏的类也没有,即.它不在SDK的PrivateFrameworks目录中,也没有标记, __attribute__((visibility("hidden")))类名也不以下划线开头.
如果您的应用因使用此功能而被拒绝,请在下方发表评论,以便我可以更新答案.
| 归档时间: |
|
| 查看次数: |
1441 次 |
| 最近记录: |