Center align form in swiftUI

Hi,

I am trying to use a form for a username/password login screen

By default, the form aligns to the top of the screen, but I want it center aligned vertically and horizontally.

Any ideas on how to do that? This is how it looks right now

I want this form center aligned vertically on the screen

You could:

  • embed the form in a VStack { }
  • set the frame of VStack:
   VStack {
        Form {
            TextField("UserName", text: $user)
            TextField("Password", text: $pswd)
       }
    }
    .frame(width: 400, height: 150, alignment: .center)  // adjust size as needed
Center align form in swiftUI
 
 
Q