Structure

ToggleStyleConfiguration

The properties of a toggle instance.

Declaration 宣言

struct ToggleStyleConfiguration

Overview 概要

When you define a custom toggle style by creating a type that conforms to the ToggleStyle protocol, you implement the makeBody(configuration:) method. That method takes a ToggleStyleConfiguration input that has the information you need to define the behavior and appearance of a Toggle.

The configuration structure’s label reflects the toggle’s content, which might be the value that you supply to the label parameter of the init(isOn:label:) initializer. Alternatively, it could be another view that SwiftUI builds from an initializer that takes a string input, like init(_:isOn:). In either case, incorporate the label into the toggle’s view to help the user understand what the toggle does. For example, the built-in switch style horizontally stacks the label with the control element.

The structure’s isOn property provides a Binding to the state of the toggle. Adjust the appearance of the toggle based on this value. For example, the built-in button style fills the button’s background when the property is true, but leaves the background empty when the property is false. Change the value when the user performs an action that’s meant to change the toggle, like the button does when tapped or clicked by the user.

Topics 話題

Getting the Label View

Managing the Toggle State

See Also 参照

Creating a Toggle from a Configuration