Structure

Text

A view that displays one or more lines of read-only text.

Declaration

@frozen struct Text

Topics

Creating a Text View

init<S>(S)

Creates a text view that displays the specified content.

init(LocalizedStringKey, tableName: String?, bundle: Bundle?, comment: StaticString?)

Creates a text view that displays localized content identified by a key.

init(verbatim: String)

Creates a text view that displays the specified string.

Choosing a Font

func font(Font?) -> Text

Sets the default font for text in the view.

func fontWeight(Font.Weight?) -> Text

Sets the font weight of the text.

struct Font

An environment-dependent font.

Styling the View’s Text

func bold() -> Text

Applies a bold font weight to the text.

func italic() -> Text

Applies italics to the text.

func underline(Bool, color: Color?) -> Text

Applies an underline to the text.

func strikethrough(Bool, color: Color?) -> Text

Applies a strikethrough to the text.

func baselineOffset(CGFloat) -> Text

Sets the baseline offset for the text.

func tracking(CGFloat) -> Text

Sets the tracking for the text.

func kerning(CGFloat) -> Text

Sets the spacing, or kerning, between two characters.

Fitting Text into Available Space

func allowsTightening(Bool) -> View

Sets whether text can compress the space between characters when necessary to fit text in a line.

func minimumScaleFactor(CGFloat) -> View

Sets the minimum amount that text scales down to fit the available space.

func truncationMode(Text.TruncationMode) -> View

Sets the truncation mode for lines of text that are too long to fit in the available space.

enum Text.TruncationMode

The kinds of truncation to perform when a line of text is too long to fit into the available space.

Handling Multiline Text

func lineLimit(Int?) -> View

Sets the maximum number of lines that text can occupy in the view.

func lineSpacing(CGFloat) -> View

Sets the amount of space between lines of text in the view.

enum TextAlignment

An alignment position for text along the horizontal axis.

Controlling the Layout Direction

func flipsForRightToLeftLayoutDirection(Bool) -> View

Sets whether the view flips its contents horizontally when the layout direction is right-to-left.

Combining Text Views

static func + (Text, Text) -> Text

Concatenates the text in two text views in a new text view.

Comparing Text Views

static func == (Text, Text) -> Bool

Indicates whether two text views are equal.

static func != (Text, Text) -> Bool

Indicates whether two text views are not equal.

Applying Standard Modifiers

View Modifiers

Configure this view and the views it contains by applying standard modifiers.

Relationships

Conforms To

See Also

Text

struct TextField

A control that displays an editable text interface.

struct SecureField

A control into which the user securely enters private text.

struct Font

An environment-dependent font.