iOS15 UINavigationBarAppearance 隐藏电池/时间图标 (UIStatusBarStyle)

iOS15 UINavigationBarAppearance hide battery / time icons (UIStatusBarStyle)

在 iOS15 我无法再设置为黑色

UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().barTintColor = UIColor(hexString: "#000000")
UINavigationBar.appearance().barStyle = UIBarStyle.black

我已经通过更改解决了这个问题

let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
appearance.backgroundColor = .black
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]

UINavigationBar.appearance().standardAppearance = appearance;
UINavigationBar.appearance().scrollEdgeAppearance = UINavigationBar.appearance().standardAppearance;

但现在我遇到了缺少电池/时钟图标的问题

在您的 UINavigationController 覆盖 preferredStatusBarStyle 和 return .lightContent

class MyNavigationController: UINavigationController {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
}

更改状态栏样式 info.plist

1: 将 UIViewControllerBasedStatusBarAppearance 设置为 false

<key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>

2:添加状态栏样式键,设置样式如Light Content

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>