Framework

KLGlassSegments

KLGlassSegments provides a segmented control with a shared interaction model for SwiftUI and UIKit. The control can use the platform glass treatment where available and has a material fallback for older supported systems. Selection, reselection, drag selection, accessibility, and Reduce Motion are explicit parts of the control rather than side effects of the visual style. The package supports iOS 17+ and macOS 14+, has no runtime dependencies, and is released under MIT by Koen Lee.

Overview

KLGlassSegmentedControl(
    segments: [
        KLGlassSegment(id: "timeline", title: "Timeline", systemImage: "clock"),
        KLGlassSegment(id: "places", title: "Places", systemImage: "mappin")
    ],
    selection: $selection,
    floatingAction: KLGlassFloatingAction(
        systemImage: "plus",
        accessibilityLabel: "Add",
        action: composeAction
    )
)

KLGlassSegment keeps an ID, title, optional normal and selected SF Symbols, optional custom images, selected tint, and accessibility identifier. KLGlassFloatingAction supplies an independent action button and can define its size and haptic behavior. For UIKit, create KLGlassSegmentedUIKitControl, call setSegments(_:), then call applySelection(_:) when the host selection changes. onReselect reports a tap on the already selected segment. updateStyle(_:) applies a new KLGlassSegmentStyle without replacing the control. KLGlassSegmentMetrics controls title and icon sizes, content spacing, height, padding, and whether titles are shown. KLGlassInteractionConfiguration controls selection haptics and drag behavior at accessibility sizes. KLGlassSegmentStyle separates the active tint, inactive tint, indicator tint, container material, fallback material, and action foreground. The control observes Reduce Motion and avoids depending on a transition animation for state correctness. Hosts can also set isReduceMotionEnabled on the UIKit control when the preference is managed outside UIKit.

Guides

KLGlassSegments · Swift Package documentation