Skip to content

ChronoPicker: A powerful and customizable date and time picker for SwiftUI, offering enhanced features and flexibility beyond the default DatePicker.

License

Notifications You must be signed in to change notification settings

Kn3cht/ChronoPicker

Repository files navigation

ChronoPicker

Platforms License: MIT

SPM Tests Release

ChronoPicker is a highly customizable and lightweight SwiftUI date picker component designed for seamless integration into your iOS and macOS applications. With support for optionals, custom disabled dates, theming, and localization, ChronoPicker provides the flexibility you need to create a tailored user experience.

image

Features

  • 🛠 Custom Disabled Dates: Disable specific dates or ranges based on your business logic, perfect for blackout periods, holidays, or availability constraints.
  • 🎨 Customizability: Fully customize the appearance, including colors, fonts, and styles, to seamlessly match your app's design.
  • 🌍 Localization: Built-in support for multiple languages, adapting automatically to the user's locale and calendar settings.

Installation

Add ChronoPicker to your project using Swift Package Manager (SPM):

  1. Open your Xcode project.
  2. Go to File > Add Packages.
  3. Enter the repository URL:
https://github.com/yourusername/ChronoPicker
  1. Select the version or branch you'd like to use.

If you are using a Package.swift, add ChronoPicker as following:

let package = Package(
  name: "Your Project Name",
  dependencies: [
    .package(url: "https://github.com/Kn3cht/ChronoPicker/releases", from: "<version>") // Checkout https://github.com/Kn3cht/ChronoPicker/releases
  ],
  ...
)

Usage

ChronoPicker is designed with a usage pattern inspired by SwiftUI's standard DatePicker. However, unlike the standard DatePicker, ChronoPicker allows the selected date to be nil. This makes it ideal for scenarios where selecting a date is optional, such as forms or filters.

Basic Example

import SwiftUI
import ChronoPicker

struct ContentView: View {
    @State private var selectedDate: Date? = Date()

    var body: some View {
        ChronoPicker($selectedDate)
            .padding()
    }
}

Date Range Ricker

ChronoDatePicker has been updated to support date range selection, allowing users to choose a start and end date in addition to single-date selection. This enhancement makes it ideal for use cases like booking systems, scheduling, and other applications requiring date ranges.

import SwiftUI
import ChronoPicker

struct RangePickerExample: View {
    
    @State private var selectedDateRange: DateRange = DateRange(startDate: Date(), endDate: Calendar.current.date(byAdding: .day, value: 4, to: Date()))
    
    var body: some View {
        VStack {
            ChronoDatePicker($selectedDateRange)
            Text(selectedDateRange.description)
        }
    }
}
image

Disabled Dates

ChronoPicker's dateDisabled callback function offers unparalleled flexibility compared to traditional range-based disabling. While ranges are sufficient for basic use cases, the callback function allows you to define complex, dynamic rules for disabling dates.

image

This approach ensures maximum flexibility, making ChronoPicker suitable for any scheduling or availability-related scenario.

// Callback: Disable weekends
ChronoPicker(
    $selectedDate,
    dateDisabled: { date in
        Calendar.current.isDateInWeekend(date)
    }
)

// Range: Disable all dates after today
ChronoPicker(
    $selectedDate,
    in: ..<Date()
)

Custom Date Rendering

ChronoPicker provides full flexibility for rendering dates by allowing you to override the default date view with your custom design. This feature is perfect for scenarios where you want to display additional information (e.g., events, availability) or apply unique styles to specific dates.

ChronoDatePicker(
    $selectedDate,
    customDateView: { date, selected, adjacent in
        // Your custom view
    })

More Examples

Checkout further examples here.

Requirements

  • iOS 15.0
  • macOS 16.0

About

ChronoPicker: A powerful and customizable date and time picker for SwiftUI, offering enhanced features and flexibility beyond the default DatePicker.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages