King
King

Reputation: 2035

NavigationView height irregular swiftui

I have a NavigationView and added a title. The problem is it looks weird when I run it.

var body: some View {
    NavigationView {
        Form {
            Section {
                Text("Hello World")
            }
        }
        .navigationBarTitle("SwiftUI", displayMode: .inline)
    }
}

The image looks weird. How can I make the navigation height look better just like UIKIt Navigation Bar

enter image description here

Upvotes: 4

Views: 1766

Answers (1)

Bradley Mackey
Bradley Mackey

Reputation: 7708

You have a double-nested NavigationView. The view that you are showing in your example is already being presented from a NavigationView, so you don't need to create an additional view. This is because the navigation view context is preserved when you use a NavigationLink.

Try removing it:

var body: some View {
    Form {
        Section {
            Text("Hello World")
        }
    }
    .navigationBarTitle("SwiftUI", displayMode: .inline) 
}

Upvotes: 9

Related Questions