Discussion 議論
Because this value is a Binding
, you can both read and write it in your implementation of the make
method when defining a custom Toggle
. Access it through that method’s configuration
parameter.
Read this value to set the appearance of the toggle. For example, you can choose between empty and filled circles based on the is
value:
Image(systemName: configuration.isOn
? "checkmark.circle.fill"
: "circle")
Write this value when the user takes an action that’s meant to change the state of the toggle. For example, you can toggle it inside the action
closure of a Button
instance:
Button {
configuration.isOn.toggle()
} label: {
// Draw the toggle.
}