how to remove iOS 15 extra top padding in swiftui InsetGroupedListStyle?

Viewed 3120

I have a InsetGroupedListStyle List in SwiftUI and noticed an extra top padding added in iOS 15. How can I control or remove this?

List {
    Section(header: Text("Header")) {
        // some content
    }
}
.listStyle(InsetGroupedListStyle())

Here is iOS 14:

enter image description here

and iOS 15:

enter image description here

2 Answers

For fixing this problem you can use the headerProminence

Section("Header") {
  // some content
}
.headerProminence(.increased)

iOS 15 vs 14

To fix the problem with table view

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

UPDATED: I think I found the solution for this specific case:

tableView.tableHeaderView = .init(frame: .init(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))

I had a similarly frustrating issue, doing this helped me

List {
    Section(header: Text("Header")) {
        // some content
    }
}
.listStyle(PlainListStyle())

Note this changed the colours of my headers

Related