Menu

DatePicker

Skip support for SwiftUI.DatePicker.

The following example screens and source code is from SkipUI’s Showcase sample app DatePickerPlayground.swift

Android screenshot for DatePicker component (light mode) iPhone screenshot for DatePicker component (light mode) iPhone screenshot for DatePicker component (dark mode) Android screenshot for DatePicker component (dark mode)
import SwiftUI

struct DatePickerPlayground: View {
    @State var selectedDate = Date.now

    var body: some View {
        ScrollView {
            VStack(spacing: 16.0) {
                DatePicker(selection: $selectedDate) {
                    Text("Viewbuilder init")
                }
                DatePicker("String init", selection: $selectedDate)
                VStack {
                    Text(".labelsHidden():")
                    DatePicker("Label", selection: $selectedDate)
                }
                .labelsHidden()
                DatePicker(".buttonStyle(.plain)", selection: $selectedDate)
                    .buttonStyle(.plain)
                DatePicker(".disabled(true)", selection: $selectedDate)
                    .disabled(true)
                DatePicker(".foregroundStyle(.red)", selection: $selectedDate)
                    .foregroundStyle(.red)
                DatePicker(".tint(.red)", selection: $selectedDate)
                    .tint(.red)
                DatePicker("Date only", selection: $selectedDate, displayedComponents: .date)
                DatePicker("Time only", selection: $selectedDate, displayedComponents: .hourAndMinute)
            }
            .padding()
        }
        .toolbar {
            PlaygroundSourceLink(file: "DatePickerPlayground.swift")
        }
    }
}