GlassSlider
| Identifier | glass-slider |
| Module | SPGlassForms |
| Kind | native-wrapper — the system Slider, tinted with the theme's primary colour |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Selection/GlassSliderExample.swift |
Minimal usage
swift
@State private var volume = 0.5
GlassSlider("Volume", value: $volume)Variants
| Variant | Use |
|---|---|
in: |
Bounds. 0...1 by default. |
step: |
Distance between two values; without it the slider is continuous. |
format: (a FormatStyle) |
.percent, .currency(code:), .number.precision(…). |
| trailing closure | Any formatting, for measurements for example. |
showsValue: false |
Hides the value next to the title. |
showsBoundLabels: true |
Formatted minimum and maximum at both ends of the track. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
title |
LocalizedStringKey |
— | Title above the slider; also its accessibility label. |
value |
Binding<Double> |
— | The value. |
in |
ClosedRange<Double> |
0...1 |
Bounds. |
step |
Double? |
nil |
Step. |
format |
FormatStyle or (Double) -> String |
number, up to 2 decimals | Text of a value. |
showsValue |
Bool |
true |
Value next to the title. |
showsBoundLabels |
Bool |
false |
Bound labels. |
onEditingChanged |
@MainActor (Bool) -> Void |
{ _ in } |
Drag started (true) or ended (false). |
States
Idle, dragging (onEditingChanged), focused and disabled (.disabled(_:)) are drawn by the system.
Advanced example
swift
GlassSlider("Temperature", value: $celsius, in: 16...28, step: 0.5, showsBoundLabels: true,
onEditingChanged: { if !$0 { thermostat.commit(celsius) } }) { value in
Measurement(value: value, unit: UnitTemperature.celsius)
.formatted(.measurement(width: .abbreviated, usage: .asProvided))
}GlassSliderMath.snapped(_:in:step:) gives the value a slider with these bounds and step would hold, for code that sets the value itself.
Accessibility
- The slider is the system's adjustable element: VoiceOver swipes up and down, arrow keys work on macOS and with a keyboard on iPad.
- Its accessibility value is the formatted text ("21.5 °C", "60 %"), not the raw number.
- The value shown next to the title uses monospaced digits, so the layout does not jitter while dragging.
- When title and value do not fit on one line (large text, long title), the value moves under the title.
Limits
Doubleonly; convert other numeric types in the binding.- The track, the thumb and its glass are drawn by the system.
- The size of a VoiceOver adjustment is the step when there is one, otherwise the system's default increment.
- VoiceOver output and keyboard adjustment were not exercised on a running device here.