TechnologiesSwiftUI

TitleAndIconLabelStyle struct

iOSmacOStvOSwatchOSvisionOSiOS 14.5+✓ renders

A label style that shows both the title and icon of the label using a

How it works

TitleAndIconLabelStyle is the LabelStyle that renders a Label with both its title and its icon, the icon leading the text. Because a Label carries a title and an image but defers its appearance to the surrounding style, you reach for this style when you want to guarantee that both halves are shown together — regardless of a context that might otherwise hide one. You apply it through the .titleAndIcon static accessor on labelStyle(_:), making it the explicit counterpart to the icon-only and title-only styles.

  1. Build the label from a title and a system image

    A Label pairs a text title with an icon; the style decides which parts appear. Here Label("Downloads", systemImage: "arrow.down.circle.fill") supplies both, giving TitleAndIconLabelStyle two elements to lay out side by side.

  2. Select the style with .labelStyle(.titleAndIcon)

    The labelStyle(_:) modifier sets the label style for a view. Passing the .titleAndIcon shorthand resolves to a TitleAndIconLabelStyle instance, as in .labelStyle(.titleAndIcon), so the label always shows the icon followed by the title.

  3. Rely on the standard icon-then-title layout

    TitleAndIconLabelStyle composes the icon and title in a horizontal arrangement with the system's default spacing — you don't size or order them yourself. Both Label("Downloads", ...) and Label("Favorites", systemImage: "star.fill") adopt that identical arrangement once the style is applied.

  4. Tune appearance with ordinary view modifiers

    Because the style only governs composition, you shape color and size with the usual modifiers. .foregroundStyle(.orange) on the Favorites label tints both its icon and text, and .font(.title3) on the enclosing stack scales every styled label together.

Try it — Change one label's .labelStyle(.titleAndIcon) to .labelStyle(.iconOnly) and watch its text disappear while the title-and-icon label beside it keeps showing both.

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.

TitleAndIconLabelStyle.swift
struct TitleAndIconLabelStyleDemo: View {
    var body: some View {
        VStack(alignment: .leading, spacing: 16) {
            Label("Downloads", systemImage: "arrow.down.circle.fill")
                .labelStyle(.titleAndIcon)
            Label("Favorites", systemImage: "star.fill")
                .labelStyle(.titleAndIcon)
                .foregroundStyle(.orange)
        }
        .font(.title3)
        .padding()
    }
}
Live preview
Downloads Favorites
Downloads Favorites
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →