Compose SwiftUIv0.4.0
esc
GuideAPIGitHub
View

DatePicker

A control that selects a date.

iOS 17.0+macOS 14.0+tvOS: unavailable (no-op)watchOS 10.0+
fun DatePicker(title: String, selection: Double, modifier: Modifier = Modifier, displayedComponents: DatePickerComponents? = null, onSelectionChange: (Double) -> Unit)

Overview

Dates are passed as seconds since 1970, as Double.

DatePicker(title = "…", selection = 0.0, onSelectionChange = { value -> })

This is the Kotlin form of SwiftUI DatePicker.init(_:selection:displayedComponents:): SwiftUI documentation. In Swift it reads:

nonisolated init<S>(_ title: S, selection: Binding<Date>, displayedComponents: DatePicker<Label>.Components = [.hourAndMinute, .date]) where S : StringProtocol

Topics

Creating a DatePicker

fun DatePicker(selection: Double, modifier: Modifier = Modifier, displayedComponents: DatePickerComponents? = null, onSelectionChange: (Double) -> Unit, content: @Composable () -> Unit)
SwiftUI DatePicker.init(selection:displayedComponents:label:)
fun DatePicker(title: String, selection: Double, modifier: Modifier = Modifier, displayedComponents: DatePickerComponents? = null, onSelectionChange: (Double) -> Unit)
SwiftUI DatePicker.init(_:selection:displayedComponents:)
fun DatePicker(titleResource: LocalizedKey, selection: Double, modifier: Modifier = Modifier, displayedComponents: DatePickerComponents? = null, onSelectionChange: (Double) -> Unit)
SwiftUI DatePicker.init(_:selection:displayedComponents:)
fun DatePicker(titleKey: LocalizedKey? = null, selection: Double? = null, displayedComponents: DatePickerComponents? = null, modifier: Modifier = Modifier, onSelectionChange: ((Double) -> Unit)? = null)
SwiftUI DatePicker · (e.g. Image(systemName = SFSymbol.star)).

Methods

fun DatePickerSelection(titleKey: LocalizedKey, selection: Double, modifier: Modifier = Modifier, displayedComponents: DatePickerComponents? = null, onSelectionChange: (Double) -> Unit)
SwiftUI DatePicker.init(_:selection:displayedComponents:)