SP GlassKit1.1.0

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.

GlassSlider running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-slider

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-slider
ModuleSPGlassForms
Kindnative-wrapper — the system Slider, tinted with the theme's primary colour
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Selection/GlassSliderExample.swift

Minimal usage

Swift
@State private var volume = 0.5

GlassSlider("Volume", value: $volume)

Variants

VariantUse
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 closureAny formatting, for measurements for example.
showsValue: falseHides the value next to the title.
showsBoundLabels: trueFormatted minimum and maximum under both ends of the track.
showsTicks: trueA 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

ParameterTypeDefaultMeaning
titleLocalizedStringKey—Title above the slider; also its accessibility label.
valueBinding<Double>—The value.
inClosedRange<Double>0...1Bounds.
stepDouble?nilStep.
formatFormatStyle or (Double) -> Stringnumber, up to 2 decimalsText of a value.
showsValueBooltrueValue next to the title.
showsBoundLabelsBoolfalseBound labels.
showsTicksBoolfalseTick 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

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

  • Double only; 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

Complete example (compiled with the package)
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

Identifierglass-slider
Version1.1.0
Depends onglass-foundation, glass-stepper
FrameworksSwiftUI
Public symbolsGlassSliderMath, GlassSlider
LicenceMIT
Manifestmanifest.json

Files