Home > Software design >  SwiftUI: How to remove spacing between 2 sections? (iOS16)
SwiftUI: How to remove spacing between 2 sections? (iOS16)

Time:01-09

How to remove spacing between 2 sections.

enter image description here

This is my code

NavigationStack {
            List {
                Section {
                    NavigationLink( value: Color.mint) {
                        HStack {
                            Image(systemName: "person").font(.system(size: 25)).padding(.trailing)
                            Text("Hi hello").font(.anuRegular(16))
                        }.frame(minHeight: 45)
                    }
                }
                Section {
                    NavigationLink( value: Color.mint) {
                        HStack {
                            Image(systemName: "person").font(.system(size: 25)).padding(.trailing)
                            Text("Hi hello").font(.anuRegular(16))
                        }.frame(minHeight: 45)
                    }
                }
            }
            .navigationDestination(for: Color.self) { color in
               
            }
            .navigationTitle("Categories")
        }

I've tried this method below from other stacks, but it doesn't work

init() {
           UITableView.appearance().sectionFooterHeight = 0
        }

CodePudding user response:

You can set the list style but then you will have to style the section cell yourself.

These two style will get rid of the space, see here for a detailed explanation about list styles

  • .listStyle(.inset)
  • .listStyle(.plain)
  • Related