TechnologiesSwiftUIControls and Style Configurations

LabeledContent struct

iOSmacOStvOSwatchOSvisionOSiOS 16.0+✓ renders

A container for attaching a label to a value-bearing view.

How it works

Use LabeledContent to pair a descriptive label with an associated value or view, presenting them as a single coherent row. It expresses the common "label on one side, content on the other" relationship declaratively, so SwiftUI can apply the correct alignment, spacing, and styling for the surrounding context rather than leaving you to position the two pieces by hand. Reach for it whenever you're displaying a read-only attribute, a setting's current value, or a detail field in a settings screen, inspector, or summary list.

  1. Pair a title with a value using LabeledContent

    The most direct initializer takes a localized title string and a value, rendering the title as the label and the value as trailing content. LabeledContent("Username", value: "appleseed") and LabeledContent("Storage", value: "128 GB") each produce a labeled row from two simple strings, with no manual layout required.

  2. Supply custom content with a trailing closure

    When the value is more than plain text, use the initializer that takes a title and a @ViewBuilder content closure. The label stays a string while the content becomes any view you build. In LabeledContent("Status") { Text("Active").foregroundStyle(.green) }, the closure supplies a styled Text as the trailing content, letting you color, format, or compose it however you like.

  3. Let the container drive label and value alignment

    LabeledContent doesn't fix its own geometry; it adapts to its container, which is why it reads as a tidy two-column row inside a Form. Placing the rows in Form gives each one the platform-standard leading label, trailing value, and inter-row spacing automatically, so Username, Status, and Storage line up consistently.

  4. Restyle rows with labeledContentStyle()

    Because LabeledContent conforms to the styling system, you can apply the .labeledContentStyle() modifier to switch presentations or attach your own LabeledContentStyle to a row or an enclosing view. This lets you change how the label and content are arranged across an entire section without rewriting each LabeledContent call.

Try it — Change LabeledContent("Status", value:)-style row by replacing the Text("Active").foregroundStyle(.green) content with a multi-line view, and watch the value column grow while the Status label stays vertically aligned to it.

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.

LabeledContent.swift
struct LabeledContentDemo: View {
    var body: some View {
        Form {
            LabeledContent("Username", value: "appleseed")
            LabeledContent("Status") {
                Text("Active")
                    .foregroundStyle(.green)
            }
            LabeledContent("Storage", value: "128 GB")
        }
        .padding()
    }
}
Live preview
Username appleseed Status Active Storage 128 GB
Username appleseed Status Active Storage 128 GB
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →