Components / Selection

Segmented Control

Click or drag tabs to explore the selection indicator.

CupertinoSegmentedControl View source ↗

Playground

Live Compose · Wasm
Preview

Click or drag inside the preview to try it out.

Properties

Usage example

Kotlin code for the current playground settings.

Example.kt
kotlin
import androidx.compose.runtime.*import androidx.compose.foundation.layout.*import androidx.compose.ui.Modifierimport androidx.compose.ui.unit.dpimport zone.ien.hig.*import zone.ien.hig.theme.*import androidx.compose.foundation.Imageimport androidx.compose.ui.layout.ContentScaleimport org.jetbrains.compose.resources.painterResourceimport zone.ien.hig.composeapp.generated.resources.Resimport zone.ien.hig.composeapp.generated.resources.glass_landscapeimport androidx.compose.foundation.backgroundimport com.kyant.backdrop.backdrops.rememberLayerBackdropimport com.kyant.backdrop.backdrops.layerBackdropimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.Alignment
@OptIn(ExperimentalCupertinoApi::class)@Composablefun Example() { CupertinoTheme(colorScheme = lightColorScheme(accent = Color(0xFF007AFF))) { val backdrop = rememberLayerBackdrop() Box(Modifier.fillMaxSize()) { Image(painterResource(Res.drawable.glass_landscape), contentDescription = null, modifier = Modifier.matchParentSize().layerBackdrop(backdrop), contentScale = ContentScale.Crop) Column(Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically)) { var selected by remember { mutableIntStateOf(0) } CupertinoSegmentedControl(selectedTabIndex = selected, backdrop = backdrop) { listOf("All", "Favorites", "Recent").forEachIndexed { index, title -> CupertinoSegmentedControlTab( isSelected = selected == index, onClick = { selected = index }, ) { CupertinoText(title) } } } } } }}

Run examples inside CupertinoTheme. For components using backdrop, attach layerBackdrop to the background content.

The background uses the sample app's glass_landscape resource. Replace it with an image from your project.