I want to create a form in which all textfield need to start from the same alignment, like in below image it does not start from the same alignment. First name, last name and Phone number all textFields are not aligned properly in a single vertical line.
VStack(){
HStack(){
Text("First Name")
TextField("First name", text: $name).textFieldStyle(RoundedBorderTextFieldStyle())
}
HStack(){
Text("Last Name")
TextField("Last Name", text: $name).textFieldStyle(RoundedBorderTextFieldStyle())
}
HStack(){
Text("Phone number")
TextField("Phone number", text: $name).textFieldStyle(RoundedBorderTextFieldStyle())
}
Spacer()
}.padding(10)
or more flexible solution
You can use
GeometryReader
to access device size andframe
to set fixed width forText
s. For example:This will align your TextFields: