Xcode SwiftUI:(Mac)如何在没有空格的情况下填充列表行背景

Xcode SwiftUI:(Mac)如何在没有空格的情况下填充列表行背景,xcode,list,swiftui,Xcode,List,Swiftui,我想用特定颜色填充所有列表行背景,我做了以下简单操作: struct ContentView: View { var body: some View { List(0 ..< 5) { index in VStack { Text("Placeholder") } .frame(minWidth: 0, maxWidth: .infinity, minHeight:

我想用特定颜色填充所有列表行背景,我做了以下简单操作:

struct ContentView: View {
    var body: some View {
        List(0 ..< 5) { index in
           VStack {
                Text("Placeholder")
            }
            .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
            .background(Color(.orange))
        }
    }
}
struct ContentView:View{
var body:一些观点{
列表(0..<5){中的索引
VStack{
文本(“占位符”)
}
.frame(最小宽度:0,最大宽度:。无穷大,最小高度:0,最大高度:。无穷大)
.背景(颜色(.橙色))
}
}
}
但结果在行周围包含一个空格:


那么,如何填充所有行背景?

在列表中使用此修饰符:

.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
这里有一个可行的方法(在beta 6中,因为
.listRowInsets()
似乎已被破坏),但感觉不是一个很好的答案。您可以使用负填充来强制背景在列表行之外绘制(您可能需要稍微修改这些值):

struct ContentView:View{
var body:一些观点{
列表(0..<5){中的索引
VStack{
文本(“占位符”)
}
.frame(最小宽度:0,最大宽度:。无穷大,最小高度:0,最大高度:。无穷大)
.背景(颜色(.橙色))
.padding(.top,-6)
.padding(.bottom,-6)
.padding(.leading,-18)
.padding(.training,-18)
}
}

}

如果希望所有行的颜色相同

struct ContentView: View {
  var body: some View {
    List(0 ..< 5) { index in
       ......
    }
    .colorMultiply(.orange)
}
struct ContentView:View{
var body:一些观点{
列表(0..<5){中的索引
......
}
.colorMultiply(.橙色)
}

希望这有帮助!

您测试了什么版本?Beta 6,但请记住:我的应用程序在Mac而不是iPhone上。请确保在列表中的每个元素上使用它。请参阅好的临时解决方案!
struct ContentView: View {
  var body: some View {
    List(0 ..< 5) { index in
       ......
    }
    .colorMultiply(.orange)
}