UIDatePicker设定最大时间和最小时间
-(UIDatePicker *)XSDataPicker{
if (!_XSDataPicker) {
_XSDataPicker = ({
UIDatePicker * picker = [[UIDatePicker alloc]initWithFrame:CGRectZero];
picker.datePickerMode = UIDatePickerModeDate;
// NSDate * date = [NSDate dateWithString:@"2000-01-01" format:@"yyyy-MM-dd" timeZone:[NSTimeZone systemTimeZone] locale:[NSLocale currentLocale]];
NSCalendar * gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents * dateComponts = [[NSDateComponents alloc]init];
[dateComponts setYear:-18];
NSDate * date = [gregorian dateByAddingComponents:dateComponts toDate:[NSDate date] options:0];
picker.date = date;
picker.maximumDate = date;
NSDate * minidate = [NSDate dateWithString:@"1900-01-01" format:@"yyyy-MM-dd" timeZone:[NSTimeZone systemTimeZone] locale:[NSLocale currentLocale]];
picker.minimumDate = minidate;
picker;
});
}
return _XSDataPicker;
}
本文标题:UIDatePicker设定最大时间和最小时间
本文链接:https://www.haomeiwen.com/subject/drlaaktx.html
网友评论