SwiftUI - Incorrect padding when using GroupedListStyle() for iOS 15

Viewed 402

I have the following structure, more or less:

ZStack {
    NavigationView {
        List {
            Section(header: Text("1")
                                .padding(.top, 20)
                    footer: Text("2")
                                .padding(.bottom, 20)
                    },
                    ...
        }
        .listStyle(GroupedListStyle())
    }
}

For iOS 14 and earlier it was working properly, but in Xcode 13 beta 4/5, when running iOS 15, the padding is much bigger, as if there was a default padding added. I need to replace my values (20 in this example) with 0 in order to match the design.

Has anyone experienced such issue? Any solutions?

2 Answers

The only solution that seems to work for me is this:

List { ... }    
    .onAppear(perform: {
        UITableView.appearance().contentInset.top = -35
    })

-35 will remove almost all of the spacing, -30 is more like the spacing that was in iOS 14.

The same thing happened to me. You just have to delete your DerivedData folder. You don't need to take make any changes to your code. Took me a while to figure that out.

Related