Generic Instance Method

toggleStyle(_:)

Sets the style for toggles within this view.

Declaration

func toggleStyle<S>(_ style: S) -> some View where S : ToggleStyle

Parameters

style

The style to set.

Discussion

To set a specific style for all toggle instances within a view, use the toggleStyle(_:) modifier, as seen below:

VStack {
    Toggle("Vibrate on Ring", isOn: $vibrateOnRing)
    Toggle("Vibrate on Silent", isOn: $vibrateOnSilent)
}
.toggleStyle(SwitchToggleStyle())

See Also

Styling a Toggle

protocol ToggleStyle

A type that specifies the appearance and interaction of all toggles within a view hierarchy.

struct DefaultToggleStyle

The default toggle style.

struct SwitchToggleStyle

A toggle style that displays a leading label and a trailing switch.

struct CheckboxToggleStyle

A toggle style that displays a checkbox followed by its label.