swifttextswiftui

How to left align text in swift UI?


I am trying to align left text in Text component in Swift UI.

aling text

As you can see on above image I applied with below code but does not work. Anything missing?

Text(titleSring).frame(alignment: .trailing).background(Color.red)

Solution

  • A frame alignment is for entire view (which is square), you need multi-line text alignment, like

    Text(titleSring)
        .multilineTextAlignment(.leading)