SP GlassKit1.1.0

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.

GlassSegmentedControl 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-segmented-control

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-segmented-control
ModuleSPGlassForms
Kindnative-wrapper — the system segmented Picker, replaced by a menu Picker when the segments cannot be read
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Selection/GlassSegmentedControlExample.swift

Minimal usage

Swift
@State private var mode = "List"

GlassSegmentedControl("View", selection: $mode, options: ["List", "Grid", "Map"]) { $0 }

Variants

SituationPresentation
Two to five options whose titles fit the widthSegments
Titles wider than the available widthMenu
More options than maximumSegmentsMenu
Accessibility text sizeMenu (segments cannot wrap, so titles would be cut)
Fewer than two optionsMenu

Parameters

ParameterTypeDefaultMeaning
titleLocalizedStringKey—Name of the control: accessibility label, and label of the menu.
selectionBinding<Option>—Selected option. Option is any Hashable type.
options[Option]—Options in order.
maximumSegmentsInt5Above 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

Swift
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

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

Identifierglass-segmented-control
Version1.1.0
Depends onglass-foundation
FrameworksSwiftUI
Public symbolsGlassSegmentedLayout, Presentation, GlassSegmentedControl
LicenceMIT
Manifestmanifest.json

Files