How it works
DefaultLabelStyle is the label style SwiftUI applies to a Label when you don't request a more specific one. It conforms to LabelStyle, and its makeBody(configuration:) pairs the label's icon and title in the standard, platform-appropriate arrangement — typically the icon leading the text. Reach for it when you want to opt back in to that system behavior explicitly, for example to override a different style inherited from an enclosing view, or to make the default arrangement clear at the call site.
Build the label with an icon and a title
A Label is the view DefaultLabelStyle acts on: it carries both a title and an icon, and the style decides how the two are composed. Here
Label("Mail", systemImage: "envelope.fill")supplies the text and an SF Symbol that the default style lays out side by side.Apply the style with labelStyle(_:)
The labelStyle(_:) modifier sets the LabelStyle for a label and the labels beneath it in the hierarchy. Passing
DefaultLabelStyle()selects the system's standard icon-plus-title presentation, as on the firstLabel("Mail", ...).Instantiate it with DefaultLabelStyle()
DefaultLabelStyle has a no-argument initializer — there are no parameters to configure, because it simply defers to the platform's standard layout. You write
DefaultLabelStyle()directly, and SwiftUI handles icon and title placement for the current context.Reach the same style through .automatic
The static
automaticmember on LabelStyle resolves to the context-appropriate default, which is DefaultLabelStyle in ordinary use. The secondLabel("Favorites", ...)uses.labelStyle(.automatic)and renders the same way as the explicitDefaultLabelStyle()above it, since both ask for the standard arrangement.
.labelStyle(DefaultLabelStyle()) on the Mail label to .labelStyle(.iconOnly) and watch the title disappear while the default-styled Favorites label keeps both its icon and text.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 DefaultLabelStyleDemo: View {
var body: some View {
VStack(alignment: .leading, spacing: 16) {
Label("Mail", systemImage: "envelope.fill")
.labelStyle(DefaultLabelStyle())
Label("Favorites", systemImage: "star.fill")
.labelStyle(.automatic)
}
.font(.title2)
.padding()
}
}