Eric
Eric

Reputation: 672

SwiftUI vertical alignment with Navigation view

I try to align content on top of page. It works but as soon as I add a NavigationView, it doesn't work anymore.

import SwiftUI
struct Stats: View {
    var body: some View {
        NavigationView {    // <- OK without navigation view
            VStack {
                Text("Stats")
                Spacer()
            }
        }
    }
}

Seems a basic problem, but didn't succeed to work it out :( Thanks

Upvotes: 0

Views: 1317

Answers (2)

Eric
Eric

Reputation: 672

Regards to Emilio's réponse, here is the solution.

import SwiftUI
struct Stats: View {
    var body: some View {
        NavigationView {
            VStack {
                Text("Stats")
                Spacer()
            }
            .navigationBarHidden(true)
        }
    }
}

Take care to apply navigationBarHidden to the Stack and not NavigationView.

Upvotes: 2

Mariam Sargsyan
Mariam Sargsyan

Reputation: 94

You just need to hide NavigationBar.

 NavigationView {   
             VStack {
                 Text("Stats")
                 Spacer()
                               }
                     .navigationBarTitle("")
                     .navigationBarHidden(true)
             
         }

Upvotes: 1

Related Questions