[英]Why background color of List is different while presenting view in SwiftUI?
我正在呈现视图(AddItemView)中实现列表。 我希望任何视图中的背景颜色都与 List 相同。
struct HomeView: View {
@State private var showAddItemView: Bool = false
var body: some View {
NavigationView {
List(0..<9, id: \.self) { i in
Text("Row \(i)")
}
.navigationTitle("Home")
.navigationBarItems(trailing:
Button("Add") {
showAddItemView.toggle()
})
.sheet(isPresented: $showAddItemView) {
AddItemView()
}
}
}
}
struct AddItemView: View {
init(){
UITableView.appearance().backgroundColor = .clear
}
var body: some View {
NavigationView {
List(0..<9, id: \.self) { i in
Text("Row \(i)")
}.background(Color(UIColor.systemGroupedBackground))
.listStyle(InsetGroupedListStyle())
.navigationBarTitle("Add Item View", displayMode: .inline)
}
}
}
上面的代码是用 InsetGroupedListStyle 创建简单的列表。 但是在呈现视图时背景颜色不同(在我的例子中是 AddItemView)。
我已经尝试过https://stackoverflow.com/a/58427518/7084910
如何在呈现视图中设置列表的背景颜色,就像在任何普通列表中一样。 红色/黄色/绿色可以设置为列表,“但是”我希望与 HomeView 中的普通列表相同,可以在明暗模式下工作。
用这个:
var body: some View {
NavigationView {
List(0..<9, id: \.self) { i in
Text("Row \(i)")
}
.colorMultiply(Color.red)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.