Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reducing space between sections for grouped List in SwiftUI?

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.

like image 244
Dirts Avatar asked Jun 22 '20 08:06

Dirts


2 Answers

You can add it outside the view like this

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

        var body: some View {}
    }
like image 95
moudstar Avatar answered Sep 27 '22 18:09

moudstar


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.

like image 20
Trevor Avatar answered Sep 27 '22 16:09

Trevor