GlassSlider
System slider with bounds, step, a readable value and VoiceOver adjustment.
- System control
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-slider
Drawn by the system. GlassKit configures it and leaves the glass to the system.
CaptureInstallation
spglass add glass-sliderCopies the sources and their dependencies into your project. Set up the CLI.
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")
import SPGlassKit| 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
@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 under both ends of the track. |
showsTicks: true | A mark under the track for each step (quarter marks for a continuous slider or more than 20 steps); the marks up to the value take the primary colour. |
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. |
showsTicks | Bool | false | Tick marks under the track (1.1). |
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
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.
- Tick marks and bound labels are decoration, hidden from VoiceOver. The marks are lined up with the thumb's travel using an approximation of the system metrics (
GlassSliderMath.tickFractions(in:step:)gives their positions). - 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.
Example
import SwiftUI
import SPGlassKit
public struct GlassSliderExample: GlassExample {
public static let componentID = "glass-slider"
@State private var brightness = 0.6
@State private var temperature = 21.0
@State private var budget = 1500.0
@State private var locked = 0.3
@State private var isDragging = false
public init() {}
public var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 24) {
GlassSlider("Brightness", value: $brightness, format: .percent.precision(.fractionLength(0)))
GlassSlider("Temperature", value: $temperature, in: 16...28, step: 0.5, showsBoundLabels: true) { value in
Measurement(value: value, unit: UnitTemperature.celsius)
.formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number.precision(.fractionLength(1))))
}
GlassSlider(
"Monthly budget",
value: $budget,
in: 0...5000,
step: 250,
format: .currency(code: "CAD").precision(.fractionLength(0)),
showsBoundLabels: true,
showsTicks: true,
onEditingChanged: { isDragging = $0 }
)
Text(isDragging ? "Adjusting…" : "Released")
.font(.caption)
.foregroundStyle(.secondary)
GlassSlider("Locked by policy", value: $locked)
.disabled(true)
}
.padding()
}
}
}
#Preview("GlassSlider") { GlassSliderExample().glassTheme(.ocean) }
Registry entry
| Identifier | glass-slider |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation, glass-stepper |
| Frameworks | SwiftUI |
| Public symbols | GlassSliderMath, GlassSlider |
| Licence | MIT |
| Manifest | manifest.json |
Files
Forms/Selection/GlassSlider.swift11088 bytes · sha256 6de3bca06a01…