Joe
Joe

Reputation: 11

SwiftUI - Align Text in a VStack

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)

Upvotes: 1

Views: 3310

Answers (2)

Asperi
Asperi

Reputation: 257709

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)

Upvotes: 4

Jeshurun Roach
Jeshurun Roach

Reputation: 66

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

Upvotes: 2

Related Questions