如何 color/remove SwiftUI 列表中最后一行和倒数第二行之间的分隔符?

How to color/remove the separator between last and second to last row in a SwiftUI List?

我正在使用简单的 SwiftUI 列表,例如

List {
  Text("A")
  Text("A")
  Text("A")
}

我已经通过添加 UITableView.appearance().separatorColor = .clear 设法移除了标准分隔线,但是在最后一个元素和倒数第二个元素之间似乎还有另一个细长的浅灰色分隔线:

如何移除此分隔线或更改其颜色?

您可以将 ScrollViewForEach 一起使用,而不是默认的 List。它将没有默认样式,您可以定义自己的样式。

struct ContentView: View {
    @State private var words = (1...50).map{ String([=10=]) }
    var body: some View {
        GeometryReader { geometry in
            ScrollView {
                ForEach(self.words, id: \.self) { word in
                    Text(word)
                }
                    .frame(width: geometry.size.width)
            }
        }
    }
}

I've already managed to remove the standard dividers by adding UITableView.appearance().separatorColor = .clear

改用

UITableView.appearance().separatorStyle = .none