TechnologiesSwiftUI

AccessoryLinearCapacityGaugeStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A gauge style that displays bar that fills from leading to trailing

How it works

AccessoryLinearCapacityGaugeStyle is a built-in GaugeStyle that draws a gauge as a horizontal bar whose fill represents how much of its range is currently consumed, much like a battery or storage meter. It's designed for compact, accessory-sized contexts such as widgets, complications, and inline status displays, where a single linear capacity reading communicates progress toward a limit at a glance. Reach for it when your value naturally reads as "how full" something is rather than a position on a dial.

  1. Apply the style with .gaugeStyle(.accessoryLinearCapacity)

    You don't instantiate this struct directly; you select it through the gaugeStyle(_:) modifier using the static shorthand. In the example, .gaugeStyle(.accessoryLinearCapacity) swaps the gauge's default rendering for the linear capacity bar, restyling every part of the Gauge it's attached to.

  2. Feed it a normalized value through Gauge

    The style renders whatever Gauge provides, so the bar's fill is driven by the gauge's value. Here Gauge(value: level) passes level, a Double in the default 0...1 range, and the capacity bar fills proportionally — 0.65 produces a roughly two-thirds-full bar.

  3. Provide the label and currentValueLabel

    The style positions the gauge's label and current-value text around the bar. The trailing-closure label Text("Battery") names the gauge, and the currentValueLabel: closure Text("\(Int(level * 100))%") supplies the readout the capacity style shows alongside the fill.

  4. Color the fill with .tint(_:)

    Because the style draws a solid capacity bar, tint(_:) controls the color of the filled portion. In the example .tint(.green) paints the consumed region green, the same lever you'd use to signal state — for instance shifting toward red as the value nears its limit.

Try it — Change @State private var level = 0.65 to 0.1, then to 0.95, and watch the .accessoryLinearCapacity bar shrink and grow to match the fraction it represents.

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.

AccessoryLinearCapacityGaugeStyle.swift
struct AccessoryLinearCapacityGaugeStyleDemo: View {
    @State private var level = 0.65

    var body: some View {
        Gauge(value: level) {
            Text("Battery")
        } currentValueLabel: {
            Text("\(Int(level * 100))%")
        }
        .gaugeStyle(.accessoryLinearCapacity)
        .tint(.green)
        .padding()
    }
}
Live preview
Battery
Battery
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →