GlassStepper
System stepper with bounds, increments and a formatted value.
- System control
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-stepper
Drawn by the system. GlassKit configures it and leaves the glass to the system.
CaptureInstallation
spglass add glass-stepperCopies 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-stepper |
|---|---|
| Module | SPGlassForms |
| Kind | native-wrapper — the system Stepper with a formatted value in its label |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Selection/GlassStepperExample.swift |
Minimal usage
@State private var guests = 2
GlassStepper("Guests", value: $guests, in: 1...12)Variants
| Variant | Use |
|---|---|
Binding<Int> | Whole numbers. |
Binding<Double> with step: | Fractional steps, without accumulated rounding noise. |
format: | Any text for the value: units, currency, percent. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
title | LocalizedStringKey | — | Title; also the accessibility label. |
value | Binding<Int> or Binding<Double> | — | The value. |
in | ClosedRange | — | Bounds. |
step | Int or Double | 1 | Increment. |
format | (Value) -> String | locale-aware number | Text of the value. |
States
Idle, pressed and focused are drawn by the system. At a bound the matching button is disabled. The whole control is disabled with .disabled(_:).
Advanced example
GlassStepper("Dose", value: $dose, in: 0...2.5, step: 0.25) { value in
Measurement(value: value, unit: UnitMass.milligrams)
.formatted(.measurement(width: .abbreviated, usage: .asProvided))
}The arithmetic is the pure function GlassStepperMath.stepped(_:by:_:in:):
- steps are counted from the lower bound, so
1.5...10by2gives 1.5, 3.5, 5.5…; - ten steps of
0.1from0give exactly1.0; - a value between two steps moves to the neighbouring step, not a full step away;
- when the upper bound is not on a step (
0...10by3), incrementing from 9 stops at 10 and decrementing from 10 returns to 9.
Accessibility
- The stepper is one adjustable element: label = title, value = the formatted text, swipe up and down to change it.
- The value is visible next to the title, in monospaced digits, and moves under the title when the two do not fit on one line.
- A bound is conveyed by the disabled button, not by colour.
Limits
- No press-and-hold acceleration beyond what the system gives to the buttons.
- No direct text entry; pair the stepper with a
GlassTextFieldif typing a value is needed. - Values with more than nine decimals are outside what the rounding clean-up handles.
- GlassKit replaces the stepper's accessibility children by one adjustable element; that VoiceOver and Switch Control behave as described was not checked on a running device.
Example
import SwiftUI
import SPGlassKit
public struct GlassStepperExample: GlassExample {
public static let componentID = "glass-stepper"
@State private var guests = 2
@State private var dose = 0.5
@State private var zoom = 1.0
@State private var fixed = 3
public init() {}
public var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 20) {
GlassStepper("Guests", value: $guests, in: 1...12)
GlassStepper("Dose", value: $dose, in: 0...2.5, step: 0.25) { value in
Measurement(value: value, unit: UnitMass.milligrams)
.formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number.precision(.fractionLength(2))))
}
// The upper bound 4 is not on a step from 0.5 by 0.75: the last press stops at the bound.
GlassStepper("Zoom", value: $zoom, in: 0.5...4, step: 0.75) { value in
value.formatted(.percent.precision(.fractionLength(0)))
}
GlassStepper("Seats (fixed by your plan)", value: $fixed, in: 1...5)
.disabled(true)
}
.padding()
}
}
}
#Preview("GlassStepper") { GlassStepperExample().glassTheme(.crystal) }
Registry entry
| Identifier | glass-stepper |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassStepperMath, Direction, GlassStepper |
| Licence | MIT |
| Manifest | manifest.json |
Files
Forms/Selection/GlassStepper.swift7704 bytes · sha256 3c169f0cd9c2…