listRowInsets(_:)
使用 List()
时未按预期工作和 List(Data,id)
.在下面的示例 1 中,零插入完美地工作,而在示例 2 中它什么也不做。
示例 1:
struct ContentView: View {
var body: some View {
List {
Color.red
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
Color.blue
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
Color.yellow
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
结果:
示例 2
struct ContentView: View {
var colors: [Color] = [.red, .blue, .yellow]
var body: some View {
List(colors, id: \.self) { color in
color.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
结果:
最佳答案
我认为原因是在使用的构造函数中。 .listRowInsets
通过将文档效果 View 放置在列表中(直接)。
以下作品
var colors: [Color] = [.red, .blue, .yellow]
var body: some View {
List {
ForEach(colors, id: \.self) { color in
color.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
关于xcode - SwiftUI:listRowInsets 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58929162/