1

How to align a Text with left alignment in a VStack that is occupying more space like this

This is the code am using

VStack(alignment:.leading) {
    Text("Test")
       .font(.system(size: 10))
       .frame(maxWidth: .infinity, maxHeight: .infinity)
}.frame(maxWidth: .infinity, maxHeight: .infinity)
 .background(Color.green)
1
  • How about some padding? Commented Oct 4, 2020 at 7:00

2 Answers 2

4

You need to add alignment to Text frame, like

VStack(alignment:.leading) {
    Text("Test")
       .font(.system(size: 10))
       .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) // << here !!
}.frame(maxWidth: .infinity, maxHeight: .infinity)
 .background(Color.green)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Got the same from this question as well: stackoverflow.com/questions/60800624/…
2

Try using this modifier on your Text view: .multilineTextAlignment(.leading)

1 Comment

Helpful if you have longer text which has an automatic linebreak into multiple lines.

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.