TechnologiesSwiftUI

DefaultGaugeStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The default gauge view style in the current context of the view being

How it works

DefaultGaugeStyle is the gauge style SwiftUI applies automatically when you create a Gauge without specifying a style of your own. It conforms to GaugeStyle and renders a gauge in the form best suited to the current platform and context, so the appearance stays consistent with the system and adapts as the environment changes. Reach for it when you want the standard gauge presentation, or when you need to override an inherited style further down a view hierarchy and restore the system default.

  1. Get the default by creating a Gauge

    Every Gauge resolves to a GaugeStyle, and in the absence of any other style that resolution is DefaultGaugeStyle. The Gauge(value:) here, fed a normalized value of 0.65, is already drawn by this style even before any modifier is attached.

  2. Apply it explicitly with gaugeStyle(_:)

    The gaugeStyle(_:) modifier sets the style for a gauge and everything beneath it in the hierarchy. Passing DefaultGaugeStyle() names the system default outright, which is useful to reset to the standard look inside a subtree that an ancestor styled differently. In the example, .gaugeStyle(DefaultGaugeStyle()) makes that choice visible.

  3. Initialize with DefaultGaugeStyle()

    DefaultGaugeStyle has a single no-argument initializer; the style itself carries no configuration, because it defers all appearance decisions to the platform. You write DefaultGaugeStyle() and let the system pick the concrete rendering.

  4. Feed it the gauge's labels

    The style lays out the labels you supply to the Gauge. The primary label here, Text("Speed"), identifies the gauge, and the currentValueLabel, Text("65%"), describes its present reading; both are positioned and styled by DefaultGaugeStyle rather than by you.

  5. Let it adapt to context

    Because it is the default, this style honors the surrounding environment such as accent color, size class, and platform conventions without extra code. Wrapping the gauge in .padding() only insets it; the gauge's own form remains whatever DefaultGaugeStyle deems appropriate there.

Try it — Change Gauge(value: 0.65) to Gauge(value: 0.1) (or 0.95) and watch how DefaultGaugeStyle redraws the filled portion to reflect the new reading.

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.

DefaultGaugeStyle.swift
struct DefaultGaugeStyleDemo: View {
    var body: some View {
        Gauge(value: 0.65) {
            Text("Speed")
        } currentValueLabel: {
            Text("65%")
        }
        .gaugeStyle(DefaultGaugeStyle())
        .padding()
    }
}
Live preview
Speed
Speed
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →