DatePicker is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'DatePicker', '0.1.1'
- Import the library
import UIKit
import DatePicker
class ViewController: UIViewController {
}
- Setup
- Picker between today and 100 years from now:
let datePicker = DatePicker()
datePicker.setup() { (date) in
//Process Date returned when date changed
print("\(date)")
}) { (date) in
// Process Date returned when select button is pressed
print("\(date)")
}
- Picker with minimum and maximum dates:
let datePicker = DatePicker()
datePicker.setup(min: minDate, max: maxDate) { (date) in
//Process Date returned when date changed
print("\(date)")
}) { (date) in
// Process Date returned when select button is pressed
print("\(date)")
}
In the example below we have set minDate and maxDate to be between July 18, 2011 and September 10, 2020
- Display
- Screen Center:
datePicker.display(in: self)
- Or as Popover:
datePicker.displayPopOver(on: button, in: self)
DatePicker is available under the MIT license. See the LICENSE file for more info.