How it works
DefaultButtonLabel is the view that SwiftUI uses to present a button's content with the system's standard label treatment. When you write a button with a string or a view, SwiftUI wraps that content so it can apply the default styling, layout, and behavior a button is expected to have. You rarely name DefaultButtonLabel directly; instead you reach for it conceptually whenever you rely on the built-in look of a Button or expose its content to a button style through the style configuration's label.
Provide content to a Button
A button's label is whatever you pass as its content. SwiftUI takes that content and produces the default label presentation behind the scenes. In the example, the string
"Increment"passed toButton("Increment")becomes the labeled content that the default label renders.Pair the label with an action
The label is only the visible part of a button; the trailing closure supplies the work. Here
count += 1runs when the rendered label is tapped, so the default label and thecountupdate together form the completeButton.Let a button style decorate the label
Applying a style tells SwiftUI how to dress the default label — its background, foreground, and shape. The
.buttonStyle(.borderedProminent)modifier wraps the"Increment"label in the prominent bordered treatment without you reconstructing the label yourself.Observe the label respond to state
Because the label is a real view in the hierarchy, it participates in state-driven updates and feedback like press and disabled states. As
@State private var countchanges, the surroundingText("Taps: \(count)")redraws while the button's default label stays consistent across taps.
Button("Increment") with a view label such as Button { count += 1 } label: { Label("Increment", systemImage: "plus") } to see the default label treatment carry over to richer content.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct DefaultButtonLabelDemo: View {
@State private var count = 0
var body: some View {
VStack(spacing: 16) {
Text("Taps: \(count)")
.font(.headline)
Button("Increment") {
count += 1
}
.buttonStyle(.borderedProminent)
}
.padding()
}
}