Navigation/DSSegmentedControl
DSSegmentedControl
navigationHorizontal row of mutually exclusive segments with a sliding active indicator.
iOS 17+macOS 14+
Purpose
Switching between views or filter modes within the same screen.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| optionsreq | [(label: String, value: T, icon: String?)] | — | Segment options. |
| selectedreq | Binding<String> | — | Active segment value. |
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"),
],
selected: $viewMode
)Time range filter
Mutually exclusive time period selection.
swift
DSSegmentedControl(
options: [
(label: "Day", value: "day", icon: nil),
(label: "Week", value: "week", icon: nil),
(label: "Month", value: "month", icon: nil),
(label: "Year", value: "year", icon: nil),
],
selected: $selectedPeriod
)Composition: Dashboard with filters
Segmented control above chart.
swift
VStack(alignment: .leading, spacing: DSSpacing.lg) {
Text("Revenue Overview")
.font(.system(size: 20, weight: .semibold))
DSSegmentedControl(
options: [
(label: "Week", value: "week", icon: nil),
(label: "Month", value: "month", icon: nil),
(label: "Year", value: "year", icon: nil),
],
selected: $period
)
RevenueChart(period: period)
}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