Reputation: 17
I'm new to Swift and usually when I add a text in a VStack or an HStack it adds the text to the middle of the screen but now it's on the left for some reason. Why is that and how can I fix it?
var body: some View {
VStack(spacing: 20){
Image("logo")
.resizable()
.scaledToFit()
.frame(width: 250, height: 250)
VStack(alignment: .leading){
Text("Welcome Back").font(.system(size: 32, weight: .heavy))
Text("Sign in to continue").font(.system(size: 16, weight: .medium))
FormField(value: $email, icon: "mail", placeholder: "Email")
FormField(value: $password, icon: "lock", placeholder: "Password", isSecure: true)
Button(action: {print("")}){
Text("Sign In")
.font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
.modifier(ButtonModifiers())
}
HStack{
Text("New?")
Text("Create a new account")
}
}
.padding(.horizontal)
}
}
Upvotes: 0
Views: 134
Reputation: 1398
By default a VStack
alignment
is set to .center
, but it looks like you set the alignment
of your second VStack
to leading
, to fix that:
Change:
VStack(alignment: .leading){
// your code ...
}
to
VStack(alignment: .center){
// your code ...
}
Upvotes: 2