TechnologiesSwiftUIControls and Style Configurations

DatePickerStyleConfiguration struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The properties of a `DatePicker`.

How it works

DatePickerStyleConfiguration is the value SwiftUI hands to a custom DatePickerStyle so it can rebuild a date picker's appearance from the pieces SwiftUI has already resolved. When you write a type conforming to DatePickerStyle, its makeBody(configuration:) method receives this configuration, which carries the picker's label along with the resolved date and range state. Reach for it whenever the built-in styles aren't enough and you want full control over how a DatePicker is laid out, while still letting SwiftUI manage the underlying selection and validation.

  1. Receive the configuration in makeBody(configuration:)

    A DatePickerStyle conformance implements makeBody(configuration:), and SwiftUI passes an instance of DatePickerStyleConfiguration as the configuration argument. That single value is your entry point to everything the style needs; in BorderedDatePickerStyle the method returns some View assembled entirely from it.

  2. Place the picker's text with the label property

    The label property is a type-erased view holding whatever title was supplied at the call site, so you decide where the caption sits and how it reads. The example pulls out configuration.label and applies .font(.headline) above the control, rather than letting the default style position it.

  3. Rebuild the control with DatePicker(_:)

    DatePicker offers an initializer that takes a DatePickerStyleConfiguration directly, reconstructing a working picker bound to the same date selection without re-declaring the binding. Here DatePicker(configuration) produces the live control, and .labelsHidden() suppresses its built-in label since the style already drew one from configuration.label.

  4. Wrap the reconstructed picker in your own chrome

    Because makeBody returns an ordinary view, you can compose the configuration's parts inside any container and decorate them freely. The example arranges configuration.label and the rebuilt DatePicker in a VStack, then adds .padding() and an .overlay with a RoundedRectangle stroke to give the picker its bordered look.

  5. Apply the style with datePickerStyle(_:)

    A custom style takes effect when you attach it to a DatePicker with the .datePickerStyle(_:) modifier. In body, the standard DatePicker("Reminder", selection: $date, displayedComponents: .date) receives .datePickerStyle(BorderedDatePickerStyle()), which is what causes SwiftUI to call makeBody(configuration:) and supply the DatePickerStyleConfiguration.

Try it — Move .font(.headline) off configuration.label and instead apply a tint by adding .foregroundStyle(.blue) to it, then watch the same label text restyle while the rebuilt DatePicker(configuration) keeps working unchanged.

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.

DatePickerStyleConfiguration.swift
struct DatePickerStyleConfigurationDemo: View {
    struct BorderedDatePickerStyle: DatePickerStyle {
        func makeBody(configuration: DatePickerStyleConfiguration) -> some View {
            VStack(alignment: .leading) {
                configuration.label
                    .font(.headline)
                DatePicker(configuration)
                    .labelsHidden()
            }
            .padding()
            .overlay(
                RoundedRectangle(cornerRadius: 8)
                    .stroke(.blue, lineWidth: 1)
            )
        }
    }

    @State private var date = Date()

    var body: some View {
        DatePicker("Reminder", selection: $date, displayedComponents: .date)
            .datePickerStyle(BorderedDatePickerStyle())
            .padding()
    }
}
Live preview
Reminder April 1, 2026
Reminder April 1, 2026
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →