init(role:action:)
Creates a button that displays a default label.
Declaration
@preconcurrency nonisolated init(role: ButtonRole, action: @escaping @MainActor () -> Void)Parameters
- role:
A semantic role describing the button.
- action:
The action to perform when the user triggers the button.
Discussion
For example, the following view would display a button with a ‘x’ symbol in the toolbar.
struct NewContactSheet: View {
var body: some View {
NavigationStack {
NewContactEditor()
.toolbar {
Button(role: .cancel) {
dismissView()
}
}
}
}
}