static var automatic: DefaultToggleStyle
Self
is DefaultToggleStyle
.static var button: ButtonToggleStyle
Self
is ButtonToggleStyle
.static var checkbox: CheckboxToggleStyle
Self
is CheckboxToggleStyle
.Availability 有効性
Technology
static var `switch`: SwitchToggleStyle
{ get }
Self
is SwitchToggleStyle
.Apply this style to a Toggle
or to a view hierarchy that contains toggles using the toggle
modifier:
Toggle("Enhance Sound", isOn: $isEnhanced)
.toggleStyle(.switch)
The style produces a label that describes the purpose of the toggle and a switch that shows the toggle’s state. The user taps or clicks the switch to change the toggle’s state. The default appearance is similar across platforms, although the way you use switches in your user interface varies a little, as described in the respective Human Interface Guidelines sections:
Platform |
Appearance |
Human Interface Guidelines |
---|---|---|
iOS, iPadOS |
||
macOS |
||
watchOS |
In iOS, iPadOS, and watchOS, the label and switch fill as much horizontal space as the toggle’s parent offers by aligning the label’s leading edge and the switch’s trailing edge with the containing view’s respective leading and trailing edges. In macOS, the style uses a minimum of horizontal space by aligning the trailing edge of the label with the leading edge of the switch. SwiftUI helps you to manage the spacing and alignment when this style appears in a Form
.
SwiftUI uses this style as the default for iOS, iPadOS, and watchOS in most contexts when you don’t set a style, or when you apply the automatic
style.
static var automatic: DefaultToggleStyle
Self
is DefaultToggleStyle
.static var button: ButtonToggleStyle
Self
is ButtonToggleStyle
.static var checkbox: CheckboxToggleStyle
Self
is CheckboxToggleStyle
.