ali*_*ego 3 xcode list ios swiftui
我试图向列表中添加一个非常短的行,框架高度为 2,但列表在列表项的上方和下方添加了不需要的填充,或者限制为最小高度,但我不知道如何删除它。我制作了以下内容来说明问题:
struct ContentView: View {
var body: some View {
List {
Color.red
.frame(height: 2)
Color.blue
.frame(height: 2)
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何删除列表项上方和下方的填充?如果使用节并添加页眉或页脚,则效果相同。它不允许我有一个框架高度较小的列表条目。
在 LazyVStack 中我没有这个问题,但我需要使用一个列表。
.environment(\.defaultMinListRowHeight, 0)使每行的最小高度为 0。否则,每行的高度将始终至少为 44(默认)点。.listRowInsets(EdgeInsets())使每一行没有插图。你也可以这样做.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)),结果是一样的。struct ContentView: View {
var body: some View {
List {
Color.red
.frame(height: 5)
.listRowInsets(EdgeInsets()) /// 2.
Color.blue
.frame(height: 5)
.listRowInsets(EdgeInsets())
}
.environment(\.defaultMinListRowHeight, 0) /// 1.
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
| 归档时间: |
|
| 查看次数: |
681 次 |
| 最近记录: |