我可以在UIPicker中通过[NSDate date]设置最长日期。但有没有办法只设置最大年份。还有一件事我希望日期和月份滚动,但年度应该最多只能到2015年。
答案 0 :(得分:3)
答案 1 :(得分:1)
在属性检查器中,您可以选择设置最大值。
答案 2 :(得分:0)
我认为这会帮助你
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *currentDate = [NSDate date];
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear:30];
NSDate *maxDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
[comps setYear:-30];
NSDate *minDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
[datePicker setMaximumDate:maxDate];
[datePicker setMinimumDate:minDate];
答案 3 :(得分:0)
//Get Current Date
NSDate *currentTime = [NSDate date];
[DatePicker setMinimumDate:currentTime];
尝试设置最大日期,它将完全设置为年度
NSString *dateString = @"01-02-2010";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:dateFromString];
[datePicker setMaximumDate: dateFromString];