您可以使用.listRowInsets 定义最后一行内容插入。
下面的示例代码sn-p:
struct AddButtonInLastSection: View {
var data = [[1: [1, 2, 3, 4, 5, 6]], [2: [1, 2, 3, 4, 5, 6]], [3: [1, 2, 3, 4, 5, 6]]]
var body: some View {
VStack {
List {
ForEach(data, id: \.self) { dict in
ForEach(0 ..< dict.keys.count) { i in
Section(header: Text("Item \(dict.keys[dict.index(dict.startIndex, offsetBy: i)])")
) {
ForEach(0 ..< dict.values.count) { j in
ForEach(dict.values[dict.index(dict.startIndex, offsetBy: j)], id: \.self) { k in
if dict.keys[dict.index(dict.startIndex, offsetBy: i)] == 3 {
if k == 6{
Text("Items: \(k) last")
.listRowInsets(.init(top: 16, leading: 20, bottom: 64, trailing: 0))
}else {
Text("Items: \(k)")
}
} else {
Text("Items: \(k)")
}
}
}
}
}
}
}
Button(action: {}) {
RoundedRectangle(cornerRadius: 4)
.overlay(
Label("ADD NEW ITEM", systemImage: "plus")
.foregroundColor(.white))
}
.foregroundColor(Color.red)
.font(.headline)
.frame(height: 64)
.frame(maxWidth: .infinity)
.padding(.init(top: 0, leading: 8, bottom: 0, trailing: 8))
}
}
}