GlassSegmentedControl
Segmented picker with labels that adapt to the available width.
- System control
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-segmented-control
Drawn by the system. GlassKit configures it and leaves the glass to the system.
CaptureInstallation
spglass add glass-segmented-controlCopies 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-segmented-control |
|---|---|
| Module | SPGlassForms |
| Kind | native-wrapper — the system segmented Picker, replaced by a menu Picker when the segments cannot be read |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Selection/GlassSegmentedControlExample.swift |
Minimal usage
@State private var mode = "List"
GlassSegmentedControl("View", selection: $mode, options: ["List", "Grid", "Map"]) { $0 }Variants
| Situation | Presentation |
|---|---|
| Two to five options whose titles fit the width | Segments |
| Titles wider than the available width | Menu |
More options than maximumSegments | Menu |
| Accessibility text size | Menu (segments cannot wrap, so titles would be cut) |
| Fewer than two options | Menu |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
title | LocalizedStringKey | — | Name of the control: accessibility label, and label of the menu. |
selection | Binding<Option> | — | Selected option. Option is any Hashable type. |
options | [Option] | — | Options in order. |
maximumSegments | Int | 5 | Above this number of options the control is a menu. |
title: | (Option) -> String | — | Title of an option, already localised; a closure or a key path. |
States
The selected segment, pressed, focused and disabled (.disabled(_:)) are drawn by the system, including the Liquid Glass selection.
Advanced example
enum Period: String, CaseIterable, Hashable {
case day, week, month, year
var title: String { rawValue.capitalized } // localise in a real application
}
GlassSegmentedControl("Period", selection: $period, options: Period.allCases, title: \.title)
.onChange(of: period) { _, newValue in chart.load(newValue) }The first part of the decision is the pure function GlassSegmentedLayout.presentation(optionCount:isAccessibilitySize:maximumSegments:); the width check is done by ViewThatFits.
Accessibility
- Both presentations are system pickers: label, selected value and keyboard navigation come from the system.
- The title is always set, although segmented pickers do not display it.
- At accessibility text sizes the menu keeps every title readable in full.
Limits
- Text titles only; no symbol-only segments.
- The width check measures the segments at their natural size; whether the switch happens exactly when a title would start to truncate was not verified on a running device.
- The control takes its natural width; it does not stretch its segments to fill a wide container.
- Single selection only.
Example
import SwiftUI
import SPGlassKit
public struct GlassSegmentedControlExample: GlassExample {
public static let componentID = "glass-segmented-control"
enum Mode: String, CaseIterable, Hashable {
case list, grid, map
var title: String { rawValue.capitalized }
}
@State private var mode = Mode.list
@State private var period = "Week"
@State private var long = "Everything that happened"
@State private var weekday = "Mon"
public init() {}
public var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 24) {
GlassSegmentedControl("View", selection: $mode, options: Mode.allCases, title: \.title)
Text("Showing: \(mode.title)").font(.callout).foregroundStyle(.secondary)
GlassSegmentedControl("Period", selection: $period, options: ["Day", "Week", "Month", "Year"]) { $0 }
Text("Titles too long for the width fall back to a menu").font(.headline)
GlassSegmentedControl("Scope", selection: $long, options: ["Everything that happened", "Only what I was mentioned in", "Nothing at all, thank you"]) { $0 }
Text("More than five options: a menu").font(.headline)
GlassSegmentedControl("Day", selection: $weekday, options: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]) { $0 }
GlassSegmentedControl("Locked", selection: .constant("On"), options: ["Off", "On"]) { $0 }
.disabled(true)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
}
}
}
#Preview("GlassSegmentedControl") { GlassSegmentedControlExample() }
Registry entry
| Identifier | glass-segmented-control |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassSegmentedLayout, Presentation, GlassSegmentedControl |
| Licence | MIT |
| Manifest | manifest.json |
Files
Forms/Selection/GlassSegmentedControl.swift5139 bytes · sha256 73ee49a90345…