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 placing stuff using View's body
, it always centers it automatically.
Is there some concept that I'm missing about layout system in SwiftUI
and if not, how can I set the text alignment properties to the Text
?
You can do this via the modifier
.multilineTextAlignment(.center)
.Apple Documentation
In SwiftUI beta 3, you can center a text view with the frame modifier:
You can set alignment for Vertical stackView as leading. Like below
I guess
SwiftUI
wants us to use wrappers like stacks for such things.So instead of writing something like
Text("Hello World").aligned(.leading)
, the following is encouraged:I was able to get this to align a Text to center: