Structure

Toggle

A control that toggles between on and off states. オンおよびオフ状態の間でトグルする(同じ操作で2状態を切り替える)コントロール。

Declaration 宣言

struct Toggle<Label> where Label : View

Overview 概要

You create a toggle by providing an isOn binding and a label. Bind isOn 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: 例えば:


@State 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: テキストのみのラベルの一般的な場合に対して、あなたは便宜イニシャライザを使用できます、それはタイトル文字列(またはローカライズ文字列キー)を最初の引数としてとります、後付クロージャではなく。


@State private var vibrateOnRing = true


var body: some View {
    Toggle("Vibrate on Ring", isOn: $vibrateOnRing)
}

Styling Toggles

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 toggleStyle(_:) 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 ToggleStyle protocol.

Topics 話題

Creating a Toggle トグルを作成する

Creating a Toggle from a Configuration

Styling a Toggle トグルの体裁を整える

Supporting Types 支援を行う型

Default Implementations 省略時実装

Relationships 関係

Conforms To 次に準拠

See Also 参照

Value Inputs