0

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.

fasoh
  • 504
  • 4
  • 17
  • Does this answer your question https://stackoverflow.com/a/73154356/12299030? – Asperi Aug 11 '22 at 17:07
  • That one did not work but the answer below did the trick. Thank you! https://stackoverflow.com/a/73174782/4269720 – fasoh Aug 12 '22 at 16:17

2 Answers2

2

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

fasoh
  • 504
  • 4
  • 17
0

You can control header footer heights using listRowInsets, you can modify all insets according to your requirements.

enter image description here

Muhammad Waqas Bhati
  • 2,775
  • 20
  • 25