init(isOn : Binding<Bool>, label: () -> Label)
init(LocalizedStringKey , isOn : Binding<Bool>)
Label
is Text
.
Label
がText
である時に利用可能です。
init<S>(S, isOn : Binding<Bool>)
Label
is Text
.
Label
がText
である時に利用可能です。
Availability 有効性
Technology
struct Toggle<Label> where Label : View
You create a toggle by providing an is
binding and a label. Bind is
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:
例えば:
private var vibrateOnRing = false
var body: some View {
Toggle(isOn: $vibrateOnRing) {
Text("Vibrate on Ring")
}
}
For the common case of 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: テキストのみのラベルの一般的な場合に対して、あなたは便宜イニシャライザを使用できます、それはタイトル文字列(またはローカライズ文字列キー)を最初の引数としてとります、後付クロージャではなく。
private var vibrateOnRing = true
var body: some View {
Toggle("Vibrate on Ring", isOn: $vibrateOnRing)
}
Toggles use a default style that varies based on both the platform and the context. For more information, read about the automatic
toggle style.
You can customize the appearance and interaction of toggles by applying styles using the toggle
modifier. You can apply built-in styles, like 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 Toggle
protocol.
init(isOn : Binding<Bool>, label: () -> Label)
init(LocalizedStringKey , isOn : Binding<Bool>)
Label
is Text
.
Label
がText
である時に利用可能です。
init<S>(S, isOn : Binding<Bool>)
Label
is Text
.
Label
がText
である時に利用可能です。
init(ToggleStyleConfiguration )
Label
is ToggleStyleConfiguration.Label
.struct ToggleStyleConfiguration
func toggleStyle <S>(S) -> some View
protocol ToggleStyle
var body: some View
typealias Body
struct Slider
struct Stepper