Toggle
struct · iOS 13.0+ · SDK 27.1
nonisolated struct Toggle<Label> where Label : ViewA control that toggles between on and off states. You create a toggle by providing an `isOn` binding and a label. Bind `isOn` to a Boolean property that determines whether the toggle is on or off. Set the label to a view that visually describes the purpose of switching between toggle states. For example: @State private var vibrateOnRing = false var body: some View { Toggle(isOn: $vibrateOnRing) { Text("Vibrate on Ring") } } For the common case of ``Label`` based labels, you can use the convenience initializer that takes a title string (or localized string key) and the name of a system image: @State private var vibrateOnRing = true var body: some View { Toggle( "Vibrate on Ring", systemImage: "dot.radiowaves.left.and.right", isOn: $vibrateOnRing ) } For text-only labels, you can use the convenience initializer that takes a title string (or localized string key) as its first parameter, instead of a trailing closure: @State private var vibrateOnRing = true var body: some View { Toggle("Vibrate on Ring", isOn: $vibrateOnRing) } For cases where adding a subtitle to the label is desired, use a view builder that creates multiple `Text` views where the first text represents the title and the second text represents the subtitle: @State private var vibrateOnRing = false var body: some View { Toggle(isOn: $vibrateOnRing) { Text("Vibrate on Ring") Text("Enable vibration when the phone rings") } } > Note: This behavior does not apply to ``ToggleStyle/button``. ### Styling toggles Toggles use a default style that varies based on both the platform and the context. For more information, read about the ``ToggleStyle/automatic`` toggle style. You can customize the appearance and interaction of toggles by applying styles using the ``View/toggleStyle(_:)`` modifier. You can apply built-in styles, like ``ToggleStyle/switch``, to either a toggle, or to a view hierarchy that contains toggles: VStack { Toggle("Vibrate on Ring", isOn: $vibrateOnRing) Toggle("Vibrate on Silent", isOn: $vibrateOnSilent) } .toggleStyle(.switch) You can also define custom styles by creating a type that conforms to the ``ToggleStyle`` protocol.
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
18 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
Toggle.init(isOn:label:)
callback cannot propagate synchronous failure
Toggle.init(sources:isOn:label:)
This declaration needs Swift generic type arguments. (no canonical witness for C)
Toggle.body
This protocol needs associated types that cannot yet cross the bridge.
Toggle.init(_:sources:isOn:)
This declaration needs Swift generic type arguments. (no canonical witness for C)
Toggle.init(_:sources:isOn:)
This declaration needs Swift generic type arguments. (no canonical witness for C)
Toggle.init(_:sources:isOn:)
This declaration needs Swift generic type arguments. (no canonical witness for C)
Toggle.init(_:systemImage:isOn:)
The iOS SDK compiler rejected this binding: referencing initializer 'init(_:systemImage:isOn:)' on 'Toggle' requires the types 'AnyView' and 'Label<Text, Image>' be equivalent
Toggle.init(_:systemImage:isOn:)
The iOS SDK compiler rejected this binding: referencing initializer 'init(_:systemImage:isOn:)' on 'Toggle' requires the types 'AnyView' and 'Label<Text, Image>' be equivalent
Toggle.init(_:systemImage:isOn:)
The iOS SDK compiler rejected this binding: referencing initializer 'init(_:systemImage:isOn:)' on 'Toggle' requires the types 'AnyView' and 'Label<Text, Image>' be equivalent
Toggle.init(_:systemImage:sources:isOn:)
This declaration needs Swift generic type arguments. (no canonical witness for C)
Toggle.init(_:systemImage:sources:isOn:)
This declaration needs Swift generic type arguments. (no canonical witness for C)
Toggle.init(_:systemImage:sources:isOn:)
This declaration needs Swift generic type arguments. (no canonical witness for C)
Toggle.init(_:image:isOn:)
The iOS SDK compiler rejected this binding: referencing initializer 'init(_:image:isOn:)' on 'Toggle' requires the types 'AnyView' and 'Label<Text, Image>' be equivalent
Toggle.init(_:image:isOn:)
The iOS SDK compiler rejected this binding: referencing initializer 'init(_:image:isOn:)' on 'Toggle' requires the types 'AnyView' and 'Label<Text, Image>' be equivalent
Toggle.init(_:image:isOn:)
The iOS SDK compiler rejected this binding: referencing initializer 'init(_:image:isOn:)' on 'Toggle' requires the types 'AnyView' and 'Label<Text, Image>' be equivalent
Toggle.init(_:image:sources:isOn:)
This declaration needs Swift generic type arguments. (no canonical witness for C)
Toggle.init(_:image:sources:isOn:)
This declaration needs Swift generic type arguments. (no canonical witness for C)
Toggle.init(_:image:sources:isOn:)
This declaration needs Swift generic type arguments. (no canonical witness for C)