美文网首页
UIDatePicker设定最大时间和最小时间

UIDatePicker设定最大时间和最小时间

作者: guoguojianshu | 来源:发表于2021-01-17 09:19 被阅读0次
    -(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