0

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)
            
        }
    }

enter image description here

0

1 Answer 1

2

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 ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.