SwiftUI text-alignment

后端 未结 9 1544
逝去的感伤
逝去的感伤 2020-12-29 00:42

Among the many properties of the Text view, I couldn\'t find any related to text alignment. I\'ve seen in a demo that it automatically handles RTL, and when pla

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 01:10

    We need to align the Text and not the Stack it's in. So calling multilineTextAlignment(.center) and setting the line limits I can be able to see the texts aligned to center. I don't know why I have to set the line limits, I thought it would expand if you have a large text.

    Text("blahblah")
            .font(.headline)
            .multilineTextAlignment(.center)
            .lineLimit(50)
    

提交回复
热议问题