Reducing space between sections for grouped List in SwiftUI?

Viewed 4321

I've been trying to reduce the space between sections in a list with the GroupedListStyle() applied without any luck.

Grouped list image

Code from above screenshot:

struct ContentView: View {
    var body: some View {
        List {
            Section {
                Text("Hello, World!")
                Text("Hello, World!")
                Text("Hello, World!")
            }
            Section {
                Text("Hello, World!")
            }
            Section {
                Text("Hello, World!")
                Text("Hello, World!")

            }
        }.listStyle(GroupedListStyle())
    }
}

Any suggestions would be greatly appreciated.

2 Answers

You can add it outside the view like this

    struct ContentView: View {
        init() {
           UITableView.appearance().sectionFooterHeight = 0
        }

        var body: some View {}
    }

I don't like this solution but I thought back to how UITableView works and guessed that it was probably the footer spacing causing this.

I added:

UITableView.appearance().sectionFooterHeight = 0

to the init of the view and that seems to have worked.

I am aware that this sets that appearance globally so potentially it will be good to reset that value when the view disappears.

Related