如何隐藏UIDatePicker中的未来日期,以便用户只选择过去和当前的生日.
我搜索很多来源,但我无法获得所需的结果.
这是我的代码,
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]]; }
如果任何身体知道解决方案,请给出建议.我真的很感激你
解决方法
以下是防止未来日期选择的简单代码:
dateofBirthDatePicker.maximumDate=[NSDate date];