9

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

George
  • 25,988
  • 10
  • 79
  • 133
alionthego
  • 8,508
  • 9
  • 52
  • 125
  • 1
    This might help: https://stackoverflow.com/questions/68155090/extra-padding-above-table-view-headers-in-ios-15 – aheze Sep 24 '21 at 01:23
  • This is useful but doesn't help in my case as the issue is not the section header top padding but actually the entire List top padding. – alionthego Sep 24 '21 at 01:49
  • I'm wondering if it could be related to new refresh controls added to list in iOS15 – alionthego Sep 24 '21 at 01:52

2 Answers2

8

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))
user16930239
  • 6,319
  • 2
  • 9
  • 33
5

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

yawnobleix
  • 1,204
  • 10
  • 21