如何删除 swiftui InsetGroupedListStyle 中 iOS 15 额外的顶部填充?

ali*_*ego 10 ios swift swiftui swiftui-list

我在 SwiftUI 中有一个 InsetGroupedListStyle 列表,并注意到 iOS 15 中添加了额外的顶部填充。我如何控制或删除它?

List {
    Section(header: Text("Header")) {
        // some content
    }
}
.listStyle(InsetGroupedListStyle())
Run Code Online (Sandbox Code Playgroud)

这是 iOS 14:

在此输入图像描述

和 iOS 15:

在此输入图像描述

use*_*239 7

要解决此问题,您可以使用headerProminence

Section("Header") {
  // some content
}
.headerProminence(.increased)
Run Code Online (Sandbox Code Playgroud)

iOS 15 与 14

修复表视图的问题

if #available(iOS 15.0, *)
    UITableView.appearance().sectionHeaderTopPadding = 0;
Run Code Online (Sandbox Code Playgroud)

更新:我想我找到了这个特定案例的解决方案:

tableView.tableHeaderView = .init(frame: .init(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
Run Code Online (Sandbox Code Playgroud)


yaw*_*eix 6

我遇到了类似的令人沮丧的问题,这样做对我有帮助

List {
    Section(header: Text("Header")) {
        // some content
    }
}
.listStyle(PlainListStyle())
Run Code Online (Sandbox Code Playgroud)

请注意,这改变了我的标题的颜色