减少 SwiftUI 中分组列表的部分之间的空间?

问题描述 投票:0回答:4

我一直在尝试使用

GroupedListStyle()
来减少列表中各部分之间的空间,但没有任何运气。

Grouped list image

上面截图中的代码:

struct ContentView: View {
    var body: some View {
        List {
            Section {
                Text("Hello, World!")
                Text("Hello, World!")
                Text("Hello, World!")
            }
            Section {
                Text("Hello, World!")
            }
            Section {
                Text("Hello, World!")
                Text("Hello, World!")

            }
        }.listStyle(GroupedListStyle())
    }
}

如有任何建议,我们将不胜感激。

swift listview swiftui
4个回答
6
投票

您可以像这样将其添加到视图之外

    struct ContentView: View {
        init() {
           UITableView.appearance().sectionFooterHeight = 0
        }

        var body: some View {}
    }

2
投票

我不喜欢这个解决方案,但我回想一下

UITableView
的工作原理,并猜测这可能是页脚间距造成的。

我补充说:

UITableView.appearance().sectionFooterHeight = 0

到视图的初始化,这似乎有效。

我知道这会全局设置该外观,因此当视图消失时重置该值可能会很好。


1
投票

iOS 17+
列表中有一个名为
listSectionSpacing
的修饰符,您可以使用它来指定间隙

.listSectionSpacing(8)

-3
投票

您可以为您的部分使用 .listRowInsets() 并为底部使用负值。

.listRowInsets(EdgeInsets(top: 0,leading: 0,bottom: -20,trailing: 0))
© www.soinside.com 2019 - 2024. All rights reserved.