[英]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.