https://github.com/destrmz/datepickerrange
Custom date picker with the ability to select both past and future dates.
https://github.com/destrmz/datepickerrange
appdevelopment datepicker datepickerrange iosdevelopment swift swiftui swiftuicomponents
Last synced: 12 months ago
JSON representation
Custom date picker with the ability to select both past and future dates.
- Host: GitHub
- URL: https://github.com/destrmz/datepickerrange
- Owner: DestrMZ
- Created: 2024-12-16T17:53:51.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-11T19:29:45.000Z (about 1 year ago)
- Last Synced: 2025-03-03T17:14:21.732Z (12 months ago)
- Topics: appdevelopment, datepicker, datepickerrange, iosdevelopment, swift, swiftui, swiftuicomponents
- Language: Swift
- Homepage:
- Size: 169 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DatePickerRange π
A beautiful and fully customizable date picker for selecting date ranges, with the ability to choose both past and future periods. This SwiftUI component is designed for seamless integration into any iOS 14.0+ app, offering a smooth and intuitive user experience when selecting start and end dates.
## Features
- **Customizable Date Range**: Easily select dates from both past and future periods through a user-friendly interface.
- **Auto-Scroll to Current Date**: The picker automatically scrolls to the current date when loaded.
- **Human-Readable Date Formatting**: Display selected dates in a clean and intuitive format (e.g., "4 December").
- **Responsive & Lightweight**: Built with SwiftUI, optimized for iOS 14+ with smooth animations and minimal memory usage.
- **Clear UI**: Clearly displays the selected start and end dates in the header for easy reference.
## π
Dark/Light mode

## Installation
### Swift Package Manager (SPM)
To integrate `DatePickerRange` into your project using Swift Package Manager, follow these steps:
1. Open your Xcode project.
2. Navigate to **File** -> **Add Packages**.
3. Paste the following repository URL: [https://github.com/DestrMZ/DatePickerRange.git](https://github.com/DestrMZ/DatePickerRange.git).
4. Select the desired version and add it to your project.
## Usage
Import the package into your SwiftUI view:
```swift
import DatePickerRange
```
To start working with CalendarManager, you need to create an instance of it with the required parameters:
```swift
@StateObject var calendarManager = CalendarManager(
minimumDate: Date(), // Set the minimum selectable date
maximumDate: Date().addingTimeInterval(60 * 60 * 24 * 365), // Set the maximum selectable date (1 year from today)
isFutureSelectionEnabled: false // Allow future dates? Set to true if needed
)
```
## Track Selected Dates
Using CalendarManager, you can get and update selected dates, for example, in your view.
Example:
```swift
@State var startDate: Date? = nil
@State var endDate: Date? = nil
```
You can subscribe to changes to these dates using .onChange(of:) to automatically update the values ββin your view:
```swift
DPViewController(calendarManager: calendarManager)
.onChange(of: calendarManager.startDate) { newStartDate in
startDate = newStartDate
}
.onChange(of: calendarManager.endDate) { newEndDate in
endDate = newEndDate
}
```
## Full example
Hereβs a full example using the package with bindings to your view:
```swift
import SwiftUI
import DatePickerRange
struct SelectDateView: View {
@StateObject var calendarManager = CalendarManager(
minimumDate: Date(),
maximumDate: Date().addingTimeInterval(60*60*24*365),
isFutureSelectionEnabled: false
)
@State var startDate: Date? = nil
@State var endDate: Date? = nil
var body: some View {
Group {
DPViewController(calendarManager: calendarManager)
.onChange(of: calendarManager.startDate) { newStartDate in
startDate = newStartDate
}
.onChange(of: calendarManager.endDate) { newEndDate in
endDate = newEndDate
}
}
}
}
#Preview {
SelectDateView()
}
```