跳转至
Enumeration

LayoutDirection

The different text directions used in different languages.

Declaration

enum LayoutDirection : Hashable, CaseIterable

Overview

Use this enumeration with the LayoutDirection environment property. See layoutDirection for more on accessing and changing this property.

There are two possible layout directions:

  1. leftToRight
  2. rightToLeft

Examples of left-to-right layout directions are English and Russian. Examples of right-to-left layout directions are Arabic and Hebrew.

In the example below, the left to right arrow is printed since we're in the English locale.

struct ContentView: View {
    @Environment(\.layoutDirection) var direction

    var body: some View {
        Text(direction == LayoutDirection.leftToRight ? "➡️" : "⬅️")
            .font(.title)
    }
}
A screenshot of a right facing arrow emoji centered on a screen with a white background.

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.


Type Method

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


Initializer

init(_:) Create a direction from its UITraitEnvironmentLayoutDirection equivalent.


Type Alias

AllCases A type that can represent 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

leftToRight The text is read and written from left to right.

rightToLeft The text is read and written from right to left.


Instance Property

hashValue The hash value.