【发布时间】:2019-12-01 02:21:43
【问题描述】:
我想在 SwiftUI 中更改 List 行的背景颜色,但不太清楚。这是迄今为止我编写的代码的一个更简单的版本。
struct ContentView: View {
init() {
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.black]
UINavigationBar.appearance().barTintColor = .blue
}
var body: some View {
NavigationView {
ZStack {
HStack {
List(0...10) { test in
Spacer()
self.background(Color.purple)
Text("This is a test")
Spacer()
self.background(Color.pink)
}
.background(Color.blue)
List(0...10) { test2 in
Spacer()
Text("Also a test")
.background(Color.green)
Spacer()
}
.background(Color.red)
}
}
}
.navigationBarTitle(
Text("Test"),
displayMode: .inline
)
}
}
我只想改变单元格/行背景的颜色,但它们在浅色模式下保持白色,在深色模式下保持黑色。
【问题讨论】:
-
这是stackoverflow.com/questions/56517904/… 的重复问题。请检查它可能对您有帮助的链接!