When you select the date field in a view, the date picker displays. I want to limit the scroll from a minimum 2 months less than current month and a maximum 4 months more than current month. I have seen similar examples. For example: for current month November, the month range should be September - March next year.
I tested this example, but wasn't successful.
// Configure date picker
- (void) initializeDatePicker {
_datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 600, 160)];
_datePicker.backgroundColor = [UIColor whiteColor];
_datePicker.datePickerMode = UIDatePickerModeDate;
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDate *currentDate = [NSDate date];
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setMonth:-2];
NSDate *minDate = [gregorian dateByAddingComponents:comps toDate:currentDate options:0];
[comps setMonth:4];
NSDate *maxDate = [gregorian dateByAddingComponents:comps toDate:currentDate options:0];
_datePicker.minimumDate = minDate;
_datePicker.maximumDate = maxDate;
[_datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
[_txfDateTextField setInputView:_datePicker];
selectedDate =[NSDate date];
}
UPDATE: The above code updates the date picker object. However, the problem is that there is no change in the date picker view. For the example above, I want the scroll to limit scrolling from September to March next year. This way the user doesn't get overwhelmed when he is scrolling. From a better UX point of view.