.multilineTextAlignment(.center)
seems to have no effect when the Text
is inside Form
, how can I center this item?
Form {
Text("I am left aligned")
Text("Why won't I center?").multilineTextAlignment(.center)
}
SwiftUI gives us a number of valuable ways of controlling the way views are aligned, and I want to walk you through each of them so you can see them in action. You can then use offset(x:y:) to move the text around inside that frame.
Select the text you want to Align And then press Control(ctrl)+I.
Just put \begin{center} when you want to start centering, and \end{center} when you want to stop centering. (If you want to center everything until the end of the document, you still need an \end{center} before the \end{document} at the end of the source file.
This works.
Form {
Text("I am left aligned")
Text("I am centered!")
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
}
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