SwiftUI Button Builder
You put a button together. The preview is roughly how it looks on iOS, and the Swift below is what you paste into the project. Anything left at the default stays out of the code.
Preview
Requires iOS 15
On iOS this is the same height as large. extraLarge is taller on visionOS.
The shape draws bordered and borderedProminent. On this style it stays invisible.
Generated code
This compiles as written. Replace // action with the action. Modifiers left at the default are not in the code.
Button("Save", systemImage: "star.fill") {
// action
}
.buttonStyle(.borderedProminent)
.controlSize(.large)
.buttonBorderShape(.capsule)
.tint(.orange)What the modifiers do
Label
The text is the title. With no symbol, Button("Save") is enough. An empty field uses that same placeholder in the code. The title describes the action, including for VoiceOver, and it stays in the code when you show only the symbol.
SF Symbol
With a symbol the builder writes Button("Save", systemImage: "star.fill"). That initializer is iOS 14, not iOS 17. Icon only, with no visible title: .labelStyle(.iconOnly), also iOS 14. The title stays as the VoiceOver name. The drawings in the preview are original, not Apple symbols.
Full width
.frame(maxWidth: .infinity) has to sit on the label inside the button. On the button itself the fill does not stretch. The builder switches to the label: form. That label is Text without a symbol, and Label with one.
Style
.borderedProminent fills the button with the tint and puts white text on it. .bordered puts a gray fill behind tinted text. .borderless is tinted text only, and .plain is the normal foreground color. plain and borderless are iOS 13. bordered and borderedProminent are iOS 15. iOS 26 also has .glass and .glassProminent. This builder does not write those.
Size
.controlSize is iOS 15. .regular is the default and is left out of the code. .extraLarge is iOS 17. On iPhone and iPad it resolves to .large. It is taller on visionOS. The preview uses the same height as large.
Shape
.buttonBorderShape draws the platter of bordered and borderedProminent. plain and borderless leave the shape invisible, turn the controls off, and the builder omits .buttonBorderShape. .automatic leaves the shape to the system. On current iOS that is a capsule, so the preview matches .capsule. automatic is left out of the code. capsule, roundedRectangle, and roundedRectangle(radius:) are iOS 15. .circle is iOS 17.
Tint
.tint is iOS 15 and sets the accent color on this button. With no tint, the preview uses system blue and the modifier is left out. With .destructive, the preview stays red even when you set a tint. Apple’s documentation does not say whether the system lays that tint over the red. The builder still writes both the role and the tint.
Font weight
.fontWeight is iOS 16. .regular is the default and is left out.
Role
Button("Delete", role: .destructive) marks a destructive action, on iOS 15. The button turns red: filled for borderedProminent, as the text for bordered and borderless. With a symbol it is Button("Delete", systemImage: "trash", role: .destructive). plain keeps the foreground color.
What gets left out
The builder omits whatever matches the default: size regular, shape automatic, no tint, font weight regular, no role, no symbol, no full width. plain and borderless omit the shape entirely. It always writes the style, because none of the four is the automatic default.
Which iOS version
The version is the oldest one where that call compiles, according to Apple’s documentation. The note above the preview uses the maximum of what you picked.
- Button(_:systemImage:action:)iOS 14
- Button(_:systemImage:role:action:)iOS 15
- Button(_:role:action:)iOS 15String literal since iOS 15. The LocalizedStringResource overload on the same page needs iOS 16.
- Button(role:action:label:)iOS 15
- Label(_:systemImage:)iOS 14String literal since iOS 14. The LocalizedStringResource overload on the same page needs iOS 16.
- .labelStyle(.iconOnly)iOS 14
- .buttonStyle(.plain)iOS 13
- .buttonStyle(.borderless)iOS 13
- .buttonStyle(.bordered)iOS 15
- .buttonStyle(.borderedProminent)iOS 15
- .controlSize(_:)iOS 15
- .controlSize(.extraLarge)iOS 17Same as large on iPhone and iPad. Taller on visionOS.
- .buttonBorderShape(_:)iOS 15Affects bordered and borderedProminent.
- .buttonBorderShape(.automatic)iOS 15
- .buttonBorderShape(.capsule)iOS 15
- .buttonBorderShape(.roundedRectangle)iOS 15
- .buttonBorderShape(.roundedRectangle(radius:))iOS 15
- .buttonBorderShape(.circle)iOS 17
- .tint(_:)iOS 15
- .fontWeight(_:)iOS 16
- .frame(maxWidth:)iOS 13
- ButtonRole.destructiveiOS 15