Instance Method

disabled(_:)

Adds a condition that controls whether users can interact with this view.

Declaration

func disabled(_ disabled: Bool) -> some View

Parameters

disabled

A Boolean value that determines whether users can interact with this view.

Return Value

A view that controls whether users can interact with this view.

Discussion

The higher views in a view hierarchy can override the value you set on this view. In the following example, the button isn’t interactive because the outer disabled(_:) modifier overrides the inner one:

HStack {
    Button(Text("Press")) {}
    .disabled(false)
}
.disabled(true)

See Also

Hiding and Disabling Views

func hidden() -> View

Hides this view.

Beta
func deleteDisabled(Bool) -> View

Adds a condition for whether the view hierarchy for self can be deleted.

Beta
func moveDisabled(Bool) -> View

Adds a condition for whether the view hierarchy for self can be moved.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software