Search code examples
swiftuiswiftui-listswiftui-navigationlinkswiftui-navigationview

In SwiftUI how do I decrease the size or get rid of a Section header when using InsetGroupedListStyle?


In a view like this:

struct ContentView: View {
  var body: some View {
    List {
      Section("How do I get rid of this space") {
        Text("Static content")
      }
      
      Section("How do I get rid of this space") {
        Text("Static content")
      }
      
      Section("How do I get rid of this space") {
        Text("Dynamic content")
        Text("Dynamic content")
        Text("Dynamic content")
      }
    }
  }
}

that looks like this:

enter image description here

How do I get rid of the space where the Section header is (marked with How do I get rid of this space)? I'm putting some static navigation links in that space and I prefer the insetGrouped ListStyle.

I've tried dabbling with UIKit:

UITableView.appearance().sectionFooterHeight = 0

but it doesnt get rid of the full height and applies globally. I'd like to use it only for this one list. Any help is appreciated.


Solution

  • Setting .environment(\.defaultMinListHeaderHeight, 1) and .listRowInsets(EdgeInsets(top: -20, leading: 0, bottom: 0, trailing: 0)) worked.