truncationMode
Sets the truncation mode for lines of text that are too long to fit in the available space.
Declaration
compose().truncationMode(mode: SwiftUI.TextTruncationMode)nonisolated func truncationMode(
_ mode: Text.TruncationMode
) -> some ViewParameters
The truncation mode that specifies where to truncate the text within the text view, if needed. You can truncate at the beginning, middle, or end of the text view.
Return value
A view that truncates text at different points in a line depending on the mode you select.
Discussion
Use the truncationMode(_:) modifier to determine whether text in a
long line is truncated at the beginning, middle, or end. Truncation is
indicated by adding an ellipsis (…) to the line when removing text to
indicate to readers that text is missing.
In the example below, the bounds of text view constrains the amount of
text that the view displays and the truncationMode(_:) specifies from
which direction and where to display the truncation indicator:
Text("This is a block of text that will show up in a text element as multiple lines. The text will fill the available space, and then, eventually, be truncated.")
.frame(width: 150, height: 150)
.truncationMode(.tail)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.