TechnologiesSwiftUI

GaugeStyle protocol

iOSmacOStvOSwatchOSvisionOS✓ renders

Defines the implementation of all gauge instances within a view

How it works

GaugeStyle is the protocol that defines the appearance and presentation of a Gauge, letting you swap a gauge's look without changing the value it reports. SwiftUI ships several concrete styles, and you select one with the gaugeStyle(_:) modifier rather than constructing the style directly. Reach for it when you want a gauge to read as a compact ring, a linear bar, or another shape that fits the surrounding layout — for example a dial that belongs in an accessory-sized space.

  1. Apply a style with the gaugeStyle(_:) modifier

    GaugeStyle takes effect through the gaugeStyle(_:) view modifier, which you attach to a Gauge. It sets the style for that gauge and any gauges nested inside it, so a single call propagates down the view tree. Here .gaugeStyle(.accessoryCircular) renders the gauge as a compact circular dial.

  2. Pick a built-in conforming style

    You rarely write a type that conforms to GaugeStyle yourself; instead you choose one of the standard values that conform to it. .accessoryCircular is one such style — a small ring suited to tight spaces — alongside others like linear and capacity variants that present the same value differently.

  3. Feed the style a value and labels from Gauge

    The style draws whatever the Gauge supplies: its value and the closures that build its labels. In the example Gauge(value: 0.7) provides the fill amount, the trailing Text("Speed") becomes the gauge's label, and the currentValueLabel closure returning Text("70%") supplies the readout the circular style places at its center.

  4. Refine the styled gauge with tint and layout modifiers

    Because gaugeStyle(_:) returns a regular view, you keep chaining modifiers after it. .tint(.blue) colors the style's active track, and .padding() insets the result — these compose with the chosen GaugeStyle rather than replacing it.

Try it — Change .gaugeStyle(.accessoryCircular) to .gaugeStyle(.linearCapacity) to watch the same value: 0.7 redraw as a horizontal bar instead of a ring.

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.

GaugeStyle.swift
struct GaugeStyleDemo: View {
    var body: some View {
        Gauge(value: 0.7) {
            Text("Speed")
        } currentValueLabel: {
            Text("70%")
        }
        .gaugeStyle(.accessoryCircular)
        .tint(.blue)
        .padding()
    }
}
Live preview
Speed
Speed
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →