Search code examples
swiftswiftuinavigationbarnavigationview

NavigationView introduces white space at top of screen


Introducing NavigationView seems to inject white space at the top of the screen.

enter image description here

Without it the text sits at the top.

enter image description here

The code is basic:

 var body: some View{
    NavigationView{
        VStack {
            Text("Top Title")
        ...
        Spacer()

In previous versions of iOS there used to be a command:

.navigationBarHidden(true)

but there doesn't seem to be a current equivalent. A lot of the workarounds on SO seem to steer towards removing the NavigationView. I'm using a tabBar so need it. What's your advice?


Solution

  • This should work (you might need to specify for: in some cases):

    .toolbar(.hidden)