我注意到iOS应用Things在iPhone应用中有一个带有灰色内容(不是黑色或白色)的状态栏。我在iPhone X上注意到了这一点。我的印象是,通过设置状态栏样式,您只能拥有黑色或白色内容的状态栏。
请参阅附带的屏幕截图以获取示例。
他们如何在自己的应用中实现这一目标?
编辑:我不是指状态栏的背景颜色,我的意思是状态栏中文字和图标的实际颜色。
答案 0 :(得分:4)
好的,经过一番挖掘后,我在StackOverflow上找到了this comment。
它完全符合我的要求。看起来它使用某种私有API,所以在真正的应用程序中实现可能不是最明智的事情。
具体来说,适用于我的代码如下所示。将此代码放在AppDelegate中的application(_:didFinishLaunchingWithOptions:)
。
Swift 4
if application.responds(to: Selector(("statusBar"))),
let statusBar = application.value(forKey: "statusBar") as? UIView,
statusBar.responds(to: #selector(getter: CATextLayer.foregroundColor)) {
statusBar.setValue(UIColor.gray, forKey: "foregroundColor")
}