在我的项目中,我需要显示日期 18 并锁定我尝试过的 100 年,但我知道了,但这里锁定了那一年(1912 年)的日期和月份,我还需要显示那一年的所有日期和月份( 1912)还有一件事,当我选择日期时它与时间一起显示我不想显示时间任何人都可以解决这个问题
-(IBAction)donePickerView:(id)sender
{
NSDate *minDate1 =[datePickerView date];
NSString *theDate = [NSString stringWithFormat:@"%@",minDate1];
self.dob.text = theDate;
DatePicView.hidden = TRUE;
datePickerView.hidden =TRUE;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField {
[self scrollViewToCenterOfScreen:textField];
scrlView.scrollEnabled = FALSE;
if (textField == dob)
{
DatePicView.hidden = FALSE;
datePickerView.hidden =FALSE;
NSCalendar * gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDate * currentDate = [NSDate date];
NSDateComponents * comps = [[NSDateComponents alloc] init];
[comps setYear: -18];
NSDate * maxDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: 0];
[comps setYear: -100];
NSDate * minDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: 0];
[datePickerView setMinimumDate:minDate];
[datePickerView setMaximumDate:maxDate];
[datePickerView setDate:minDate];
[dob resignFirstResponder];
}
}