Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI How to center Text in a Form?

Tags:

swiftui

.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)
}
like image 985
trapper Avatar asked Aug 16 '19 04:08

trapper


People also ask

How do I move text in SwiftUI?

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.

How do I align text in Xcode?

Select the text you want to Align And then press Control(ctrl)+I.

How do you center in latex?

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.


1 Answers

This works.

Form {
    Text("I am left aligned")
    Text("I am centered!")
    .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
}
like image 125
trapper Avatar answered Sep 20 '22 20:09

trapper