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.
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 theGaugeit's attached to.Feed it a normalized value through Gauge
The style renders whatever
Gaugeprovides, so the bar's fill is driven by the gauge'svalue. HereGauge(value: level)passeslevel, aDoublein the default 0...1 range, and the capacity bar fills proportionally —0.65produces a roughly two-thirds-full bar.Provide the label and currentValueLabel
The style positions the gauge's label and current-value text around the bar. The trailing-closure
labelText("Battery")names the gauge, and thecurrentValueLabel:closureText("\(Int(level * 100))%")supplies the readout the capacity style shows alongside the fill.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.
@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.
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()
}
}