I am using UIDatePicker control in my project. Added the UIDatePicker in xib file, and programmatically setting the constraints such as minimumDate, maximumDate to the datePicker. This is working fine in simulator, but in device I am able to select any date in datePicker.
Sample code:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.datePicker setMinimumDate:[NSDate date]];
[self.datePicker setMaximumDate:[[NSDate date] dateByAddingTimeInterval:3*24*60*60]];
}
screenshot:
Note: I am working on xcode5 - DP6.
Thanks in advance.
Add an action for the
UIControlEventValueChanged
event on theUIDatePicker
and implement checks to see if the selected date is greater than maximum date or less then the minimum date and set the date accordingly, like so:This will cause the
UIDatePicker
to scroll to the max/min date if you select a date outside the range.