Ram*_*Ram 20 objective-c uidatepicker ios
如何在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]];
}
Run Code Online (Sandbox Code Playgroud)
如果有人知道解决方案,请提出建议.我真的很感谢你.
Maw*_*oon 49
以下是防止将来选择日期的简单代码:
dateofBirthDatePicker.maximumDate=[NSDate date];
Run Code Online (Sandbox Code Playgroud)
Phi*_*son 12
在Swift 2中:
self.datePicker.maximumDate = NSDate()
在Swift 3中:
self.datePicker.maximumDate = Date()
在 Swift 4.0.3 Xcode 9 中
隐藏未来日期
self.picker.maximumDate = Date()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18393 次 |
最近记录: |