0

我有List一个Sections

    List {
        ForEach((1...3), id: \.self) { _ in
            Section(
                header: Text("My Section")
                            .font(.system(.title3))
                            .fontWeight(.bold)
                            .foregroundColor(.primary),
                content: {
                    ForEach((1...5), id: \.self) { _ in
                        Text("My Row")
                    }
                }
            )
        }
    }

这是使用 iOS 14.5 的 iPhone 8 模拟器上的结果:

iPhone8_iOS14.5

这是带有 iOS 15 的 iPhone 8 模拟器上的结果:

iPhone8_iOS15

我希望 iOS15 列表等于 iOS14.5 之一。.listStyle(PlainListStyle())我可以通过添加来删除水平填充,List但该部分的标题仍然具有不同的垂直填充。

iPhone8_iOS15_PlainList

有没有办法拥有与 iOS14.5 相同的垂直标​​题填充?

环境:

  • iOS 15 遥控器
  • XCode 13 遥控
4

3 回答 3

2

将列表的样式更改为GroupedListStyle使用.listStyle()修饰符。

.listStyle(GroupedListStyle())


没有灰色背景的标题

.listStyle(PlainListStyle())

更多信息

https://developer.apple.com/documentation/swiftui/liststyle

于 2021-09-16T16:24:45.433 回答
0

最后,最适合我的是加

if #available(iOS 15.0, *) {
    UITableView.appearance().sectionHeaderTopPadding = 0
}

在 AppDelegatedidFinishLaunchingWithOptions函数中

于 2021-09-30T14:49:18.087 回答
0

您可以尝试defaultMinListHeaderHeight在环境中设置:

List {
...
}
.environment(\.defaultMinListHeaderHeight, 16)
于 2021-09-28T07:36:14.517 回答