How to hide the future dates in UIDatePicker for user choosing only past and current year of birthdays.
I search lot of source but I can't get the desired result.
Here is my code,
dateofBirthDatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)]; dateofBirthDatePicker.datePickerMode = UIDatePickerModeDate; [dateofBirthDatePicker setBackgroundColor:DATE_PICKER_GRAY_COLOR]; // UILabel *label = [UILabel appearanceWhenContainedIn:[UITableView class],[UIDatePicker class], nil]; // label.font = HELVETICA_NEUE(24); // label.textColor = GREEN_COLOR; [dateofBirthDatePicker addTarget:self action:@selector(LabelChange:) forControlEvents:UIControlEventValueChanged]; dateofbirthTextField.inputView = dateofBirthDatePicker; [self datePickerToolBar]; } - (void)LabelChange:(id)sender { NSDateFormatter *dateFormat= [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"dd/MM/yyyy"]; dateofbirthTextField.text = [NSString stringWithFormat:@"%@", [dateFormat stringFromDate:dateofBirthDatePicker.date]]; }
If any body know the solution kindly give the suggestion. I really appreciate to you.
In the calendar widget their is an option to select max date, in which you can set the value as CurrDate(). So that future dates in the calendar would be disabled.
If you want to future date disable from today use today. getFullYear() - 10 in order to disable 10 years before which means disable from 2008.
In the Flutter date range picker, you can enable or disable the past dates by using the enablePastDates property of the calendar. When setting the enablePastDates property value as false, you can't able to select the past dates.
Here is the simple code to prevent future date selection:
dateofBirthDatePicker.maximumDate=[NSDate date];
In Swift :
dateofBirthDatePicker.maximumDate = Date()
In Swift 2:
self.datePicker.maximumDate = NSDate()
In Swift 3:
self.datePicker.maximumDate = Date()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With