TechnologiesSwiftUI

DatePickerStyle protocol

iOSmacOStvOSwatchOSvisionOS✓ renders

A type that specifies the appearance and interaction of all date pickers

How it works

DatePickerStyle is the protocol that defines the appearance and interaction behavior of a DatePicker. Rather than configuring a date picker's layout directly, you select one of the conforming styles SwiftUI provides and let it determine whether dates are entered through a compact field, a wheel, or a full calendar grid. This separates a picker's data binding from its presentation, so the same DatePicker can adapt to different contexts and platforms simply by swapping its style. Reach for it whenever the default style doesn't match the surrounding UI or the kind of date entry you want to offer.

  1. Apply a style with datePickerStyle(_:)

    You don't conform to DatePickerStyle yourself in everyday code; you apply one of the built-in conforming styles using the datePickerStyle(_:) modifier on a DatePicker or any view containing pickers. In the example, .datePickerStyle(.graphical) attaches the style to the DatePicker labeled "Departure".

  2. Choose a concrete conforming style

    SwiftUI ships several types that conform to DatePickerStyle, each exposed as a static convenience value: .graphical presents an interactive calendar and clock, .compact shows a tappable field that expands into a picker, .wheel uses spinning wheels, and .automatic defers to the platform default. The example uses .graphical to render a full calendar grid inline.

  3. Pair the style with displayedComponents

    The style governs how the picker looks, while the DatePicker's displayedComponents parameter governs which fields it offers. The two work together: here displayedComponents: .date limits entry to a calendar date, so the .graphical style draws a month grid without the time clock it would otherwise include.

  4. Style flows down through the environment

    datePickerStyle(_:) sets the style in the environment, so it applies to the DatePicker it's attached to and to any date pickers nested below it in the view hierarchy. This lets you set one style on a container and have every DatePicker inside it adopt the same appearance.

Try it — Change .datePickerStyle(.graphical) to .datePickerStyle(.wheel) and watch the same "Departure" picker switch from a calendar grid to spinning date wheels.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

DatePickerStyle.swift
struct DatePickerStyleDemo: View {
    @State private var date = Date()
    var body: some View {
        DatePicker("Departure", selection: $date, displayedComponents: .date)
            .datePickerStyle(.graphical)
            .padding()
    }
}
Live preview
April 2026 SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
April 2026 SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →