1

I'm trying to get Text to touch the left side. Right now, they all have unequal spacing on the sides. Here's my code:

struct ContentView: View { var body: some View { VStack(spacing: 20) { Text("Some long text long longgggggg long long long long long long long long long long long long") .border(Color.blue) Text("Some long text long a long long long long long long long long long long long long") .border(Color.blue) Text("Some long text long asda long long long long long long long long long long long long") .border(Color.blue) } } } 

Result:

3 Text stacked vertically, each with different widths and centered

This is what I want (achieved with HStack + Spacer()):

3 Text stacked vertically, each with different widths but aligned left

How can I do this? HStack + Spacer() doesn't seem right for multiline Text.

1 Answer 1

3

I figured it out as I was writing my question. Just add alignment: .leading to the VStack.

struct ContentView: View { var body: some View { VStack(alignment: .leading, spacing: 20) { /// here! Text("Some long text long longgggggg long long long long long long long long long long long long") .border(Color.blue) Text("Some long text long a long long long long long long long long long long long long") .border(Color.blue) Text("Some long text long asda long long long long long long long long long long long long") .border(Color.blue) } } } 

Result:

3 Text stacked vertically, each with different widths but aligned left

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.