var datePicker = UIDatePicker()
datePicker.datePickerMode = .date
// set the start date to today if you don't want to allow dates in the past
datePicker.minimumDate = Date()
// calculate +7 days
let next7Days = Calendar.current.date(byAdding: .day, value: 7, to: Date())
//set maximum date
datePicker.maximumDate = next7Days
1条答案
按热度按时间gopyfrb31#
您可以在
UIDatePicker
中设置最大日期,如下所示:这将只允许选择未来7天内的日期