0

I have a Form and a Button in a VStack, but the form takes up nearly the entire view and the button is forced at the bottom. I am trying to make the button come right after the form, but so far my attempts with padding and spacer have failed. Anyone else know how to prevent a form from taking up the entire view?

W. Churchill
  • 346
  • 1
  • 7
  • 28
Eric Chang
  • 41
  • 1

2 Answers2

0

Try moving the button into the form.

  VStack {
    Form {
      Text("blah")
      Button("blubb") { }
    }
  }

Screenshot

nine stones
  • 3,264
  • 1
  • 24
  • 36
0

You have two solutions: 1 - if you know the frame of your form, you can set the frame for the Form and set infinity height for VStack to fill the entire screen

var body: some View {
        VStack {
            Form {
                Text("blah")
            }.frame(height: 300)
            Button("blubb") { }
        }.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
    }

2 - embed the Button in Form and separate it using Section

VStack {
   Form {
      Text("blah")
      Section {
         Button("blubb") { }
      }
   }
}
Mac3n
  • 4,189
  • 3
  • 16
  • 29