我正在使用 Mac OS 中的 ListView。我正在尝试更改该 ListView 的背景颜色。但是,这并不像预期的那样容易。
我尝试在 ListView 上使用 .background(Color(.red))
属性。但那没有改变任何东西。
我只能找到 .listRowBackground(Color(.red))
这个属性对表格行有影响。但是,其他背景并没有受到影响。
我准备了一个小演示来展示:
在我的视图主体中:
VStack
{
List()
{
Text("Test")
.listRowBackground(Color.green)
Text("Test")
.listRowBackground(Color.green)
Text("Test")
.listRowBackground(Color.green)
}.background(Color(.red))
}.background(Color(.red))
这是我得到的结果:
主背景没有改变。我看过一个解决方案,可以更改UITableView.appearance
,但对于我在Mac OS上使用SwiftUI来说不可行。
提前感谢。
LazyVStack
和ForEach
不是List
的替代品(因为缺少选择和使用箭头键导航)。 - Lupurus