繁体   English   中英

当我使用 NavigationView 和 List 时,如何更改 SwiftUI 中的背景颜色?

[英]How can I change the background color in SwiftUI when I am using NavigationView and List?

我想更改背景颜色,但我使用的是 NavigationView 和 List。 这就是为什么 ZStack 方法对我不起作用的原因。

这是我的代码:

NavigationView {
    List {
        Text("Some Text")
    }

    .navigationBarTitle("Test")
}

您可以在列表中使用 .listRowBackground。

  ZStack{
        Color.blue
   NavigationView {
    ZStack{
        Color.red
       List {
        ZStack{
            Color.green
            Text("Some Text").background(Color.green).opacity(0.5)

        }.listRowBackground(Color.red)
        }
    }
       .navigationBarTitle("Test")
   }.padding()

    }
NavigationView {
    List {
         Text("Some Text")
    }
    .navigationBarTitle("Test")
}.colorMultiply(Color.green)

最后我找到了我的问题的答案:

init() {
    UITableView.appearance().backgroundColor = UIColor(named: "CustomBackgroundColor")
    UITableViewCell.appearance().backgroundColor = UIColor(named: "CustomBackgroundColor")
    UITableView.appearance().tableFooterView = UIView()
}

var body: some View {
    NavigationView {
        List {
            Text("Hello")
        }

        .navigationBarTitle("Test")
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM