跳转至
Protocol

DatePickerStyle

A type that specifies the appearance and interaction of all date pickers within a view hierarchy.

Declaration

protocol DatePickerStyle

Overview

Use this protocol with the datePickerStyle(_:) view modifier to set a DatePicker's style.

Though you cannot currently create your own date picker style, there are 6 date picker pre-made styles to choose from:

You can use the pre-defined styles like this:

struct ContentView: View {
    @State var date = Date()

    var body: some View {
        DatePicker("Choose a date 📆", selection: $date)
            .datePickerStyle(WheelDatePickerStyle())
    }
}
A gif displaying a wheel style date picker, in which the week day month and date, the hour time, the minute time, and meridiam (am/pm) can be selected separately by scrolling around a wheel; a light gray box highlights the current selections.

Check out DatePicker for more on how to make date pickers. Or see Date for more on making and using date objects.

Availability

iOS 13.0+

macOS 10.15+