Add PGCDatePickerController folder into your project.
You just need to call the PGCDatePickerController
method, and it will return a PGCDatePickerController
instance.
You can pass a Date
instance to make the default date selected
In the completion you obtain the date selected by the user.
let dateController = PGCDatePickerController.with(currentDateSelected: self.defaultDate) { [weak self] (date) in
guard let self = self else { return }
//
// Use date selected in completion
// self.defaultDate = date
//
}
Then, you need to present the view controller.
self.present(dateController, animated: false, completion: nil)
You can OPTIONALLY setup options for the DatePicker using these variables declared in DatePickerOptions
:
- minuteInterval
- mode
- minimumDate
- maximumDate
var datePickerOptions = DatePickerOptions()
datePickerOptions.minimumDate = Date()
datePickerOptions.mode = .dateAndTime
datePickerOptions.minuteInterval = 5
And send it as a parameter in the view controller creation
let dateController = PGCDatePickerController.with(currentDateSelected: self.defaultDate, withOptions: datePickerOptions) { [weak self] (date) in
guard let self = self else { return }
//
// Use date selected in completion
// self.defaultDate = date
//
}
self.present(dateController, animated: false, completion: nil)
This program is free software; you can redistribute it and/or modify it under the terms of the MIT License.