使用Swift 3.0在iOS中禁用上一个日期,月份,年份JTAppleCalendar

时间:2017-09-28 09:11:52

标签: ios jtcalendar

我正在使用这个库:
https://github.com/orazz/CalendarPopUp

我们假设我有一个用户注册日期,它是28/9/2017。现在我想只在下一个日期,月份和年份之间启用日期。 应禁用以前的日期,月份和年份。

我该怎么做?

如何禁用滚动并选择上一个日期和月份?

enter image description here

1 个答案:

答案 0 :(得分:0)

使用此选项设置最小和最大日期。您可以更改日,月,年等任何组件。

目标c

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *currentDate = [NSDate date];
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setMonth:3];
NSDate *maxDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
[comps setMonth:-3];
NSDate *minDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];   
[datePicker setMaximumDate:maxDate];
[datePicker setMinimumDate:minDate];

<强>夫特

let gregorian: NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!   
let currentDate: NSDate = NSDate() 
let components: NSDateComponents = NSDateComponents()

components.month = -3
let minDate: NSDate = gregorian.dateByAddingComponents(components,   toDate: currentDate, options: NSCalendarOptions(rawValue: 0))!

components.month = 3
let maxDate: NSDate = gregorian.dateByAddingComponents(components, toDate: currentDate, options: NSCalendarOptions(rawValue: 0))!

self.datePicker.minimumDate = minDate
self.datePicker.maximumDate = maxDate