SwiftUI 导航视图在内容之前没有足够的空间

时间:2021-07-19 08:35:47

标签: swiftui swiftui-navigationview

我有一个 SwiftUI 导航视图,里面的内容视图在导航栏和内容之间有很小的空间。这是我的代码:

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)
    }
}

}

这是应用预览中的样子:

app preview screehshot

1 个答案:

答案 0 :(得分:1)

试试这个:

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

或者您可以将其添加到列表中。

  List {
    ....
  }.padding(.top, 44)