Instance Method

disabled(_:)

Adds a condition for whether users can interact with the 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 the view.

func deleteDisabled(Bool) -> View

Adds a condition for whether the view’s view hierarchy is deletable.

func moveDisabled(Bool) -> View

Adds a condition for whether the view's view hierarchy is movable.