Overloads
2 ways to call compose().multilineTextAlignment(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().multilineTextAlignment(
alignment: SwiftUI.TextAlignment
)nonisolated func multilineTextAlignment(
_ alignment: TextAlignment
) -> some ViewParameters
alignment*SwiftUI.TextAlignmentA value that you use to align multiple lines of text within a view.
Return value
A view that aligns the lines of multiline Text instances it contains.
Discussion
Use this modifier to set an alignment for a multiline block of text.
For example, the modifier centers the contents of the following
Text view:
Text("This is a block of text that shows up in a text element as multiple lines.\("\n") Here we have chosen to center this text.")
.frame(width: 200)
.multilineTextAlignment(.center)The text in the above example spans more than one line because:
- The newline character introduces a line break.
- The frame modifier limits the space available to the text view, and by default a text view wraps lines that don't fit in the available width. As a result, the text before the explicit line break wraps to three lines, and the text after uses two lines.
The modifier applies the alignment to the all the lines of text in the view, regardless of why wrapping occurs:
The modifier has no effect on a Text view that contains only one
line of text, because a text view has a width that exactly matches the
width of its widest line. If you want to align an entire text view
rather than its contents, set the aligment of its container, like a
VStack or a frame that you create with the
View.frame(minWidth:idealWidth:maxWidth:minHeight:idealHeight:maxHeight:alignment:)
modifier.
The modifier also affects the content alignment of other text container
types, like TextEditor and TextField. In those cases, the
modifier sets the alignment even when the view contains only a single
line because view's width isn't dictated by the width of the text it
contains.
The modifier operates by setting the
EnvironmentValues.multilineTextAlignment value in the environment,
so it affects all the text containers in the modified view hierarchy.
For example, you can apply the modifier to a VStack to
configure all the text views inside the stack.
See also
More in Text and symbols.
- allowsTighteningSets whether text in this view can compress the space between characters when necessary to fit text in a line.
- autocorrectionDisabledSets whether to disable autocorrection for this view.
- baselineOffsetSets the vertical offset for the text relative to its baseline in this view.
- boldApplies a bold font weight to the text in this view.
- findDisabledPrevents find and replace operations in a text editor.
- findNavigatorProgrammatically presents the find and replace interface for text editor views.
- fontSets the default font for text in this view.
- fontDesignSets the font design of the text in this view.
- fontWeightSets the font weight of the text in this view.
- fontWidthSets the font width of the text in this view.
- interactionActivityTrackingTagSets a tag that you use for tracking interactivity.
- italicApplies italics to the text in this view.