role
TypeScriptget role(): (ButtonRole) | nullSwift declarationlet role: ButtonRole?An optional semantic role that describes the button's purpose. A value of `nil` means that the Button doesn't have an assigned role. If the button does have a role, use it to make adjustments to the button's appearance. The following example shows a custom style that uses bold text when the role is ``ButtonRole/cancel``, ``ShapeStyle/red`` text when the role is ``ButtonRole/destructive``, and adds no special styling otherwise: struct MyButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .font( configuration.role == .cancel ? .title2.bold() : .title2) .foregroundColor( configuration.role == .destructive ? Color.red : nil) } } You can create one of each button using this style to see the effect: VStack(spacing: 20) { Button("Cancel", role: .cancel) {} Button("Delete", role: .destructive) {} Button("Continue") {} } .buttonStyle(MyButtonStyle()) 