UIDatePicker设定最大时间和最小时间
2021-01-17 本文已影响0人
guoguojianshu
-(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;
}