1

I have an Hstack with two components. One is a drop-down menu, and the other is a nav link to "forgot password" page. I can't figure out why it won't go all the way to the top of the page.

I've tried inserting Spacer() on the very bottom (but within the bounds) of the HStack() code, won't move at all. I've tried putting additional objects and texts below and see if it would push up with a Spacer() below the new object, still wouldn't budge.

var body: some View {

    VStack{
        NavigationView{

        HStack{
            DropDownNewUser()
            Spacer()
            NavigationLink(destination: ForgotPasswordView()) {
                Image(systemName: "questionmark")
                    .padding(15)
                    .background(lightgold)
                    .cornerRadius(50)
                    .foregroundColor(.white)
            }
        }.padding(10).edgesIgnoringSafeArea(.all)
    }
}

enter image description here

Asperi
  • 228,894
  • 20
  • 464
  • 690
  • 1
    If you put the spacer in the HStack then you are just affecting the horizontal distribution. The spacer needs to be in the navigation view or vstack – Paulw11 May 17 '20 at 00:19

1 Answers1

2

Put VStack with Spacer inside, as below

var body: some View {
  NavigationView{
     VStack{          // << here !!
        HStack{
            DropDownNewUser()
            Spacer()
            NavigationLink(destination: ForgotPasswordView()) {
                Image(systemName: "questionmark")
                    .padding(15)
                    .background(lightgold)
                    .cornerRadius(50)
                    .foregroundColor(.white)
            }
        }.padding(10).edgesIgnoringSafeArea(.all)
        Spacer()       // << here !!
    }
  }
}
Asperi
  • 228,894
  • 20
  • 464
  • 690
  • When I do this it does not go all the way to the top (but buttons work). I then fix this by applying .padding(.top,40).edgesIgnoringSafeArea(.all) to the VStack. It works by putting it to the top but the buttons/drop-downs don't work anymore. Any way around this? – aloogobitings May 17 '20 at 17:58