Skip to content

Ljuka/CalendarDateRangePicker

Repository files navigation

CalendarDateRangePickerViewController

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Here's what it looks like:

alt text

Usage

It's as simple as:

let dateRangePickerViewController = CalendarDateRangePickerViewController(collectionViewLayout: UICollectionViewFlowLayout())
dateRangePickerViewController.delegate = self
let navigationController = UINavigationController(rootViewController: dateRangePickerViewController)
self.navigationController?.present(navigationController, animated: true, completion: nil)

Just implement the delegate methods:

protocol CalendarDateRangePickerViewControllerDelegate {
    func didCancelPickingDateRange()
    func didPickDateRange(startDate: Date!, endDate: Date!)
}

You can also set additional options to override the defaults:

dateRangePickerViewController.minimumDate = Date()
dateRangePickerViewController.maximumDate = Calendar.current.date(byAdding: .year, value: 2, to: Date())
dateRangePickerViewController.selectedStartDate = Date()
dateRangePickerViewController.selectedEndDate = Calendar.current.date(byAdding: .day, value: 10, to: Date())
dateRangePickerViewController.selectedColor = UIColor.red
dateRangePickerViewController.titleText = "Select Date Range"

Set font for navigation items:

dateRangePickerViewController.navigationTitleFont = UIFont(name: "HelveticaNeue-Light", size: 20)!
dateRangePickerViewController.navigationLeftItemFont = UIFont(name: "HelveticaNeue-Light", size: 20)!
dateRangePickerViewController.navigationRightItemFont = UIFont(name: "HelveticaNeue-Light", size: 20)!

If you need you can scroll to a specific date without selecting any:

dateRangePickerViewController.scrollToDate = Calendar.current.date(byAdding: .month, value: 3, to: Date())

And set array of disabled dates:

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
dateRangePickerViewController.disabledDates = [dateFormatter.date(from: "2018-11-13"), dateFormatter.date(from: "2018-11-21")] as? [Date]

Installation

CalendarDateRangePickerViewController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'CalendarDateRangePicker'

Author

Ljuka, [email protected]

License

CalendarDateRangePickerViewController is available under the MIT license. See the LICENSE file for more info.