Navigation/DSSegmentedControl
DSSegmentedControl
navigationHorizontal row of mutually exclusive segments with a sliding active indicator.
iOS 17+macOS 14+watchOS 10+tvOS 17+visionOS 1+
Purpose
Switching between views or filter modes within the same screen.
Interactive Reference
Live showroom
Need the full visual surface?
Screenshots do not scale well across every component, state, and variant. For the real interactive reference, import the package and launch DSShowcaseRoot().
Best for exploring:
variants, states, categories, and real app examples in one place.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| optionsreq | [(label: String, value: T, icon: String?)] | — | Segments. T is any Hashable value. |
| selectionreq | Binding<T> | — | Active segment value. |
| size | DSButtonSize | .md | Control height (.sm, .md, .lg). |
Examples
View mode switcher
Switch between list and grid views.
swift
DSSegmentedControl(
options: [
(label: "List", value: "list", icon: "list.bullet"),
(label: "Grid", value: "grid", icon: "square.grid.2x2"),
(label: "Board", value: "board", icon: "rectangle.split.3x1"),
],
selection: $viewMode
)Time range filter
Compact, text-only segments.
swift
DSSegmentedControl(
options: [
(label: "Day", value: Period.day, icon: nil),
(label: "Week", value: Period.week, icon: nil),
(label: "Month", value: Period.month, icon: nil),
],
selection: $period,
size: .sm
)When to Use
✓ Use DSSegmentedControl for:
- • Switching between 2-5 mutually exclusive views
- • Filter modes within the same screen (All, Active, Completed)
- • View mode toggles (List, Grid, Map)
- • Time period selection (Day, Week, Month)
✗ Avoid using for:
- • More than 5 options (use DSTabBar or dropdown)
- • Multi-select filters (use DSChip)
- • Navigation between different screens (use DSTabBar)
- • Binary toggles (use Toggle or DSSwitch)
Accessibility
VoiceOver
Announces 'Segmented Control, [selected option], Button, [position] of [total]'
Keyboard
- • Arrow keys to navigate
- • Space or Return to select
- • Tab to focus control
Dynamic Type
✓ Supported
Contrast
WCAG AA compliant (indicator 3:1, text 4.5:1)
Traits
.isButton for each segment.isSelected for active segmentGroup role