One Logo Pool Ball
SwiftUI · IOS API REFERENCE

PrimitiveButtonStyleConfiguration

struct · iOS 13.0+ · SDK 27.1

struct PrimitiveButtonStyleConfiguration

The properties of a button.

Members (3)

get · iOS 15.0+

role

TypeScript
get role(): (ButtonRole) | null
Swift declaration
let role: ButtonRole?

An optional semantic role describing the button's purpose. A value of `nil` means that the Button has no 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: PrimitiveButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .onTapGesture { configuration.trigger() } .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()) ![A screenshot of three buttons stacked vertically. The first says Cancel in black, bold letters. The second says Delete in red, regular weight letters. The third says Continue in black, regular weight letters.](PrimitiveButtonStyleConfiguration-role-1)

get · iOS 13.0+

label

TypeScript
get label(): PrimitiveButtonStyleConfiguration_Label
Swift declaration
let label: PrimitiveButtonStyleConfiguration.Label

A view that describes the effect of calling the button's action.

method · iOS 13.0+

trigger

TypeScript
trigger(): void
Swift declaration
func trigger()

Performs the button's action.

Skipped declarations

No declarations were skipped in this snapshot.

All SwiftUI types →