我有一个日期选择器,我想限制日期选择器显示日期和日期以及月份,但该月份不能更改,它会附加到日期。即1月15日星期五。1月15日是一个组成部分。它应该显示当天加上接下来的6天,所以一周。我不想要这一年。如何仅在Datepicker上允许日期和日期?
let gregorian: NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
let currentDate: NSDate = NSDate()
let components: NSDateComponents = NSDateComponents()
let minDate: NSDate = gregorian.dateByAddingComponents(components, toDate: currentDate, options: NSCalendarOptions(rawValue: 0))!
components.year = +7
let maxDate: NSDate = gregorian.dateByAddingComponents(components, toDate: currentDate, options: NSCalendarOptions(rawValue: 0))!
self.datepicker.minimumDate = minDate
self.datepicker.maximumDate = maxDate
你不能使用'UIDatePicker'。你需要使用'UIPickerView'。 – rmaddy
这很不幸,谢谢! – coolmac