SwiftUI Vertical List Section header padding in iOS 15

Viewed 2222

I have a List with 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")
                    }
                }
            )
        }
    }

Here is the result on an iPhone 8 simulator with iOS 14.5:

iPhone8_iOS14.5

And here the result on an iPhone 8 simulator with iOS 15:

iPhone8_iOS15

I want iOS15 list to be equal to iOS14.5 one. I can remove horizontal padding by adding .listStyle(PlainListStyle()) to the List but the header of the section still have different vertical padding.

iPhone8_iOS15_PlainList

Is there a way to have the same vertical header padding as iOS14.5 ?

Environment:

  • iOS 15 RC
  • XCode 13 RC
3 Answers

Finally, what suited me the most was to add

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

In AppDelegate didFinishLaunchingWithOptions function

You can try setting the defaultMinListHeaderHeight in the environment:

List {
...
}
.environment(\.defaultMinListHeaderHeight, 16)
Related