【发布时间】:2016-01-15 06:05:33
【问题描述】:
我有一个日期选择器,我想限制日期选择器显示日期和月份,但是月份不能更改,它附加到日期。即 1 月 15 日星期五。1 月 15 日是其中一个组成部分。它应该显示当天加上接下来的 6 天,所以一周。我不想过年。
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。 -
很不幸,谢谢!
标签: ios swift datepicker