TechnologiesSwiftUI

DefaultLabelStyle struct

iOSmacOStvOSwatchOSvisionOSiOS 14.0+✓ renders

The default label style in the current context.

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.

  1. 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.

  2. 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 first Label("Mail", ...).

  3. 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.

  4. Reach the same style through .automatic

    The static automatic member on LabelStyle resolves to the context-appropriate default, which is DefaultLabelStyle in ordinary use. The second Label("Favorites", ...) uses .labelStyle(.automatic) and renders the same way as the explicit DefaultLabelStyle() above it, since both ask for the standard arrangement.

Try it — Change .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.

DefaultLabelStyle.swift
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()
    }
}
Live preview
Mail Favorites
Mail Favorites
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →