Instance Property インスタンスプロパティ

horizontalSizeClass

The horizontal size class of this environment. この環境の水平サイズ等級。

Declaration 宣言

var horizontalSizeClass: UserInterfaceSizeClass? { get set }

Discussion 議論

You receive a UserInterfaceSizeClass value when you read this environment value. The value tells you about the amount of horizontal space available to the view that reads it. You can read this size class like any other of the EnvironmentValues, by creating a property with the Environment property wrapper:


@Environment(\.horizontalSizeClass) private var horizontalSizeClass

SwiftUI sets this size class based on several factors, including:

  • The current device type.

  • The orientation of the device.

  • The appearance of Slide Over and Split View on iPad.

Several built-in views change their behavior based on this size class. For example, a NavigationView presents a multicolumn view when the horizontal size class is UserInterfaceSizeClass.regular, but a single column otherwise. You can also adjust the appearance of custom views by reading the size class and conditioning your views. If you do, be prepared to handle size class changes while your app runs, because factors like device orientation can change at runtime.

See Also 参照

Display Characteristics