I am trying to create a profile page, in which there is a form at the bottom with various options. However when I insert a Spacer() into the VStack, the form does not move to the bottom of the screen, as it should do. I tried replacing the Form with a Text and it worked fine, moving to the bottom of the screen. So I'm assuming it has something to do with the form.

Here is my code
struct Profile: View {
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
var body: some View {
NavigationView {
VStack {
Image(systemName: "person.crop.circle")
.resizable()
.frame(width: 50, height: 50)
// .padding(.top)
Text("[email protected]")
.font(.title)
Spacer()
Form {
Section {
//menuListItem(image: "gear", label: "Settings")
menuListItem(image: "questionmark.circle", label: "Help") menuListItem(image: "info.circle", label: "About")
}
Section {
HStack {
Spacer()
Button(action: {
UserDefaults.standard.set(false, forKey: "LoggedIn")
UserDefaults.standard.set(nil, forKey: "user_id")
UserDefaults.standard.set(nil, forKey: "school_id")
self.mode.wrappedValue.dismiss()
}) {
Text("Log Out")
.font(.body)
.foregroundColor(.red)
}
Spacer()
}
}
}
}
.navigationBarTitle("Profile", displayMode: .inline)
}
}
}
struct menuListItem: View {
var image: String
var label: String
var body: some View {
HStack {
Image(systemName: image)
Text(label)
.font(.body)
}
}
}
As long as bottom of the Form is unknown(because Form is scrollable and its items start from the top), swiftUI does not know how much space should put between those two views. So Spacer() does not help.
Try this:
Give your form: for example, .frame(height: 500) or .padding(.top, 400) modifier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With