2

I've got a SwiftUI Navigation View and the content views inside have a very small amount of space between the navigation bar and the content. Here's my code:

struct TestView: View {

var body: some View {
    ZStack(alignment: .top) {
        NavigationView {
            List {
                Section(header: Text("Section Header")) {
                    NavigationLink(
                        destination: CustomDeckView(),
                        label: {
                            Text("A link")
                                .foregroundColor(AppTheme.Colors.text)
                        })
                    .preferredColorScheme(.light)
                }
            }
            .listStyle(InsetGroupedListStyle())
            .navigationBarTitleDisplayMode(.inline)
        }
        .navigationViewStyle(StackNavigationViewStyle())

        Text("Custom Font")
            .font(.custom("Pacifico-Regular", size: 27.5))
            .offset(y: -5)
    }
}

}

This is what it looks like in the app preview:

app preview screehshot

user3067870
  • 556
  • 1
  • 6
  • 17

1 Answers1

1

try this:

Section(header: Text("Section Header").padding(.top, 44)) {
 ....
}

or you can add it to the List.

  List {
    ....
  }.padding(.top, 44)
  • Thanks, @workingdog but adding padding top to the Section header Text didn't work and when I add padding top to the List, it works, however, I end up with a gap of white background colour between the nav bar and the first Section header: https://imgur.com/lf36ZPD – user3067870 Jul 19 '21 at 09:07
  • ha, I see, I'm using Xcode 13, targeting ios15, and Section header padding works in that without the blank space gap. Maybe not in older version of ios. – workingdog support Ukraine Jul 19 '21 at 09:23
  • Hey @workingdog, I'm sorry, I was editing the wrong file! Adding padding to the Section header text DOES work! :) I forgot to add the version (Xcode 14) but it works thank you so much! – user3067870 Jul 19 '21 at 09:32