关于iPhone:自定义iOS状态栏颜色

Custom iOS Status Bar Color

我注意到iOS应用"事物"在其iPhone应用中具有一个带有灰色内容(不是黑色或白色)的状态栏。 我在iPhone X上注意到了这一点。我的印象是,通过设置状态栏样式,您只能拥有带有黑色或白色内容的状态栏。

有关示例,请参见随附的屏幕截图。

他们将如何在其应用程序中实现这一目标?

编辑:我不是指状态栏的背景色,而是指状态栏中文本和图标的实际颜色。

Things Screenshot with grey statusbar


好的,经过进一步的挖掘,我在StackOverflow上找到了此评论。

正是我想要的。 看起来它使用了某种私有API,因此在实际应用中实现它可能不是最明智的选择。

具体来说,下面找到适合我的代码。 将此代码放在AppDelegate内的application(_:didFinishLaunchingWithOptions:)中。

斯威夫特4

1
2
3
4
5
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")
}