UIDatePicker
Create a Date Picker
Section titled “Create a Date Picker”let datePicker = UIDatePicker(frame: CGRect(x: 0, y: 0, width: 320, height: 200)Objective-C
Section titled “Objective-C”UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(x: 0, y: 0, width: 320, height: 200)];Setting Minimum-Maximum Date
Section titled “Setting Minimum-Maximum Date”You can set the minimum and the maximum date that UIDatePicker can show.
Minimum date
Section titled “Minimum date”[datePicker setMinimumDate:[NSDate date]];Maximum date
Section titled “Maximum date”[datePicker setMaximumDate:[NSDate date]];UIDatePicker has various picker modes.
enum UIDatePickerMode : Int { case Time case Date case DateAndTime case CountDownTimer}Setting property datePickerMode
let datePicker = UIDatePicker(frame: CGRect(x: 0, y: 0, width: 320, height: 200)datePicker.datePickerMode = .DateSetting minute interval
Section titled “Setting minute interval”You can change property minuteInterval to set the interval displayed by the minutes wheel.
The default value is 1, the maximum value is 30.
let datePicker = UIDatePicker(frame: CGRect(x: 0, y: 0, width: 320, height: 200)datePicker.minuteInterval = 15Count Down Duration
Section titled “Count Down Duration”The NSTimeInterval value of this property indicates the seconds from which the date picker in countdown-timer mode counts down. If the mode of the date picker is not CountDownTimer, this value is ignored. Maximum value is 86,399 seconds (23:59)
let datePicker = UIDatePicker(frame: CGRect(x: 0, y: 0, width: 320, height: 200)datePicker.countDownDuration = 60 * 60Remarks
Section titled “Remarks”UIDatePicker does not inherit from UIPickerView, but it manages a custom picker-view object as a subview.