'How do I vertically center form view in swiftUI?
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?
struct LoginView: View {
@State var username: String = ""
@State var password: String = ""
var body: some View {
VStack {
Form {
TextField("Username", text: $username)
TextField("Password", text: $password)
}
}
.frame(width: 400, height: 200, alignment: .center)
}
}
this is how it looks right now
I tried using a VStack and using a .frame modifier but I got a result that looked like this which is NOT what I want
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
