我在 Mac OS 中使用 ListView。我正在尝试更改该 ListView 的背景颜色。然而,这并不像预期的那么容易。
我尝试.background(Color(.red))在 ListView 上使用属性。那没有改变任何东西。
我只能找到.listRowBackground(Color(.red))哪个对表格行有影响。但是,其他背景没有受到影响。
我准备了一个小demo来演示:
在我看来身体:
VStack
{
List()
{
Text("Test")
.listRowBackground(Color.green)
Text("Test")
.listRowBackground(Color.green)
Text("Test")
.listRowBackground(Color.green)
}.background(Color(.red))
}.background(Color(.red))
Run Code Online (Sandbox Code Playgroud)
这就是我得到的结果:
主背景没有变化。我读到了一个解决方案,UITableView.appearance但在 Mac OS 的 SwiftUI 中这对我来说是不可能的。
提前致谢