Instance Method インスタンスメソッド

labelsHidden()

Hides the labels of any controls contained within this view. このビュー内に含まれるあらゆるコントロールのラベルを隠します。

Declaration 宣言

func labelsHidden() -> some View

Discussion 議論

Use this modifier when you want to omit a label from one or more controls in your user interface. For example, the first Toggle in the following example hides its label:


VStack {
    Toggle(isOn: $toggle1) {
        Text("Toggle 1")
    }
    .labelsHidden()


    Toggle(isOn: $toggle2) {
        Text("Toggle 2")
    }
}

The VStack in the example above centers the first toggle’s control element in the available space, while it centers the second toggle’s combined label and control element:

A screenshot showing a view with two toggle controls where one label

Always provide a label for controls, even when you hide the label, because SwiftUI uses labels for other purposes, including accessibility.

See Also 参照

Visibility