我有一个 UITextfield“生日”,现在点击文本字段后我有一个键盘,我想将其更改为日期选择器。
有没有人可以逐步帮助解决这个问题?我应该在我的代码中添加什么以及我需要进行哪些更改。
这是我的 UITextField“Birthady”的内容:
field = [[UITextField alloc] initWithFrame:frame];
[self.appDel.styleManager decorateTextField:field];
field.placeholder = @"Birthday";
[container addSubview:field];
self.registrationFormBirthday = field;
self.registrationFormBirthday.delegate = self;
根据乔纳森的回答,这就是我现在所拥有的:
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if textField == XtextLabel
{
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] ;
NSDate *currentDate = [NSDate date];
NSDateComponents *comps = [[NSDateComponents alloc] init] ;
[comps setYear:-0];
NSDate *maximumDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
[comps setYear:-90];
NSDate *minimumDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
[datePicker setMaximumDate:maximumDate];
[datePicker setMinimumDate:minimumDate];
datePicker.datePickerMode = UIDatePickerModeDate;
textField.inputView = datePicker;
}
}
如何在 XtextLabel 中显示所选日期并退出 datePicker?