跳转至
Structure

SwitchToggleStyle

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

Declaration

struct SwitchToggleStyle : ToggleStyle

Overview

struct ContentView: View {
    @State private var status = true
    var body: some View {
        Toggle(isOn: $status) {
            Text("Banana🍌🍌")
        }
        .toggleStyle(SwitchToggleStyle())
        .padding()
    }
}
The gif shows a switch toggle with the text "Banana🍌🍌" flipping on and off.

To apply this style to a toggle, or to a view that contains toggles, use the toggleStyle(_:) modifier.

Availability

iOS 13.0+

macOS 10.15+

watchOS 6.0+

Topics


Initializer

init() Creates a switch toggle style.

init(tint:) Creates a switch style with a tint color.


Instance Method

makeBody(configuration:) Creates a view representing the body of a toggle.


Type Alias

Body A view that represents the appearance and interaction of a toggle.