swift - SwiftUI - 导航栏颜色更改未应用于状态栏
问题描述
我有以下内容:
var body: some View {
NavigationView {
VStack {
Text("Hello")
}.navigationBarTitle("Edit Profile", displayMode: .inline)
.background(NavigationConfiguration { nc in
nc.navigationBar.barTintColor = .red
nc.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.black]
})
}.navigationViewStyle(StackNavigationViewStyle())
}
对于导航栏的配置,我有:
struct NavigationConfiguration: UIViewControllerRepresentable {
var configuration: (UINavigationController) -> Void = { _ in }
func makeUIViewController(context: UIViewControllerRepresentableContext<NavigationConfiguration>) -> UIViewController {
UIViewController()
}
func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext<NavigationConfiguration>) {
if let nc = uiViewController.navigationController {
self.configuration(nc)
}
}
}
但由于某种原因,顶部状态栏被忽略了,颜色也没有应用到它:
红色如何也应用于导航栏上方的状态栏,我希望它是相同的颜色。
我尝试了以下方法,但失败了:
init() {
UINavigationBar.appearance().backgroundColor = .red
}
解决方案
推荐阅读
- python - Micropython - 如何在 C 中创建一个继承在 C 中定义的另一种类型的类型?
- python - 更改 CSV 列中的数据格式
- r - 如何将值从一个表复制到另一个表
- html - Flex 项目溢出容器
- php - 如何在 wordpress 4.9.7 中启用站点网络?
- maven - 使用 maven 构建后 Jar 文件不在目标文件夹中 - KOTLIN
- java - 两个线程可以访问同一个类的两个不同的静态方法吗
- javafx - 如何设置滑块更改侦听器仅在 JavaFX 中释放鼠标拖动时触发?
- html - "font-style: italic" 使文本从容器中突出,切断文本
- sql - 使用 json_extract 在 JSON 数组中的所有对象中查找