How it works
ToggleStyleConfiguration carries the state and content that SwiftUI hands to a custom toggle style at render time. When you adopt the ToggleStyle protocol, the system calls your makeBody(configuration:) method and passes an instance of this type, giving you the toggle's current on/off value and its label without exposing how the toggle was originally declared. Reach for it whenever you want a checkbox, switch, or other bespoke appearance to replace the default control while still honoring the binding and label the call site supplied.
Receive the configuration in makeBody(configuration:)
Conforming to ToggleStyle requires a makeBody(configuration:) method whose parameter is a ToggleStyleConfiguration. SwiftUI constructs this value for you and invokes the method once per toggle, so you never create it yourself. In the example, CheckboxStyle declares func makeBody(configuration: ToggleStyleConfiguration) -> some View and reads everything it needs from that configuration.
Read and write the state through isOn
The isOn property is a Binding<Bool> that reflects whatever binding was passed to the Toggle. Reading configuration.isOn tells you the current state, and because it is a binding you can also drive it: the example branches on configuration.isOn to pick checkmark.square.fill versus square, and calls configuration.isOn.toggle() inside onTapGesture to flip the value when the user taps.
Place the caller's label with the label property
The label property is an opaque view that wraps the title content supplied at the toggle's call site, so your style stays reusable across different toggles. Rather than hard-coding text, you embed configuration.label into your layout; here it sits beside the checkbox Image inside an HStack, rendering the "Wi-Fi" title that the Toggle declared.
Install the style with toggleStyle()
A style only takes effect once you attach it to a toggle (or an enclosing view) with the toggleStyle() modifier, which is what triggers SwiftUI to build a ToggleStyleConfiguration and route it into your makeBody. The example wires this up with Toggle("Wi-Fi", isOn: $wifi).toggleStyle(CheckboxStyle()), so the $wifi binding becomes configuration.isOn.
Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct ToggleStyleConfigurationDemo: View {
struct CheckboxStyle: ToggleStyle {
func makeBody(configuration: ToggleStyleConfiguration) -> some View {
HStack {
Image(systemName: configuration.isOn ? "checkmark.square.fill" : "square")
.foregroundColor(configuration.isOn ? .green : .gray)
.onTapGesture { configuration.isOn.toggle() }
configuration.label
}
}
}
@State private var wifi = true
var body: some View {
Toggle("Wi-Fi", isOn: $wifi)
.toggleStyle(CheckboxStyle())
.padding()
}
}