Generic Initializer

init(_:action:)

Creates a button that generates its label from a string.

Declaration

init<S>(_ title: S, action: @escaping () -> Void) where S : StringProtocol
Available when Label is Text.

Parameters

title

A string that describes the purpose of the button’s action.

action

The action to perform when the user triggers the button.

Discussion

This initializer creates a Text view on your behalf, and treats the title similar to init(_:). See Text for more information about localizing strings.

To initialize a button with a localized string key, use init(_:action:) instead.

See Also

Creating a Button

init(action: () -> Void, label: () -> Label)

Creates a button that displays a custom label.

init(LocalizedStringKey, action: () -> Void)

Creates a button that generates its label from a localized string key.

init(PrimitiveButtonStyleConfiguration)

Creates a button based on a configuration for a style with a custom appearance and custom interaction behavior.