3

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)
2
  • you are giving align to text... so it is already in center. if you want whole red part(label) in center you need to give Alignment to HStack Commented Jan 19, 2022 at 13:15
  • Check this Commented Jan 19, 2022 at 14:02

2 Answers 2

9

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

Text(titleSring)
    .multilineTextAlignment(.leading)
Sign up to request clarification or add additional context in comments.

Comments

0

Add a Spacer in a HStack instead like this

HStack {
          Text(title)
              .font(.subheadline)
              .bold()
          Spacer()
        }

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.