跳转至
Enumeration

TextAlignment

An enum indicating available alignments for text that spans multiple-lines.

Declaration

@frozen enum TextAlignment : Hashable, CaseIterable

Overview

This is used in conjuction with multilineTextAlignment(_:), for example:

A screenshot of a text view displaying a multi-line string in the center of the screen in black text, aligned in the center of the frame.

struct ContentView: View {
    var body: some View {
        Text("Gregor's eyes then turned to the window, and the overcast weather--he could hear raindrops hitting against the metal window ledge--completely depressed him.")
            .padding(20)
            .font(.system(size: 10))
            .multilineTextAlignment(TextAlignment.center)
    }
}

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Type Property

allCases A collection of all values of this type.


Instance Method

hash(into:) Hashes the essential components of this value by feeding them into the given hasher.


Case

center Aligns each line of the text with the center of the view.

leading Aligns each line of the text to the leading edge, left in left-to-right languages, and right in right-to-left languages.

trailing Aligns each line of the text to the trailing edge, right in left-to-right languages, and left in right-to-left languages.


Type Alias

AllCases A type that can represent a collection of all values of this type.


Type Method

==(a:b:) Returns a Boolean value indicating whether two values are equal.


Instance Property

hashValue The hash value.