Post not yet marked as solved
Post marked as unsolved with 1 replies, 2,356 views
Hi Im trying to achieve this result in the image of this Stack overflow questionhttps://stackoverflow.com/questions/56623310/swiftui-login-page-layoutAs you can see I already reached this point but I don't like my implementationstruct ContentView : View {
@State var username: String = ""
var body: some View {
VStack(alignment: .leading) {
Text("Login")
.font(.title)
.multilineTextAlignment(.center)
.lineLimit(nil)
Text("Please")
.font(.subheadline)
HStack {
VStack (alignment: .leading, spacing: 20) {
Text("Username: ")
Text("Password: ")
}
VStack {
TextField($username, placeholder: Text("type something here..."))
.textFieldStyle(.roundedBorder)
TextField($username, placeholder: Text("type something here..."))
.textFieldStyle(.roundedBorder)
}
}
}.padding()
}
}Because in order to make the username and password text aligned exactly in the middle of the textfield, I had to put literal spacing value of 20 in the VStack which I don't like because most probably It won't work on different device sizes.Anyone sees a better way to achieve the same result?Thanks