Zack Shapiro
Zack Shapiro

Reputation: 6998

SwiftUI: How can I hide the large space where the title would be set but not the navigation bar?

I've been searching around on SO and I see quite a few posts asking how to hide the title bar, but all answers seem to hide the navigation bar as well. I'm looking for a solution where I can still navigate back but also where the user doesn't see the big white space before the first element rendered in my view.

Thanks

Upvotes: 3

Views: 1760

Answers (1)

Zack Shapiro
Zack Shapiro

Reputation: 6998

Just figured it out. The key here is not only to set the navigationBarTitle to "" but also to set displayMode: .inline which sets the title in the nav bar to be an empty string, so you get the nav bar without the big space for a large title below the nav bar

var body: some View {
    VStack {
       some elements in here...
    }.navigationBarTitle("", displayMode: .inline)
}

Upvotes: 7

Related Questions