I am trying to set alignment on my text inside of the Text struct but I can't find any property that does that. Code example (Updated):
VStack(alignment: .center) {
Text(optionItem.title)
.fontWeight(.heavy)
.color(optionItem.color)
.font(.system(size: 64))
.frame(width: bounds.width, height: 100, alignment: .center)
.padding(.top, 60)
Text(optionItem.description)
.lineLimit(nil)
.padding([.leading, .trailing], 40)
.frame(width: bounds.width, height: 120, alignment: .center)
.font(.system(size: 16))
}
.padding(.bottom, bounds.height * 0.55)
The Text "object" is centered but not the text inside. Image:
You should use the .multilineTextAlignment(_:)
method on the Text
element.
This works fine for me:
Text("[...]")
.lineLimit(nil)
.multilineTextAlignment(.center)
.padding(.horizontal, 40)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With