2

I am using this library:
https://github.com/orazz/CalendarPopUp

Let's say I have a date for registration of user and it's 28/9/2017. Now I want to only enable dates between next date, month and year. Previous dates, month and year should be disabled.

How can I do that?

How do I disable scrolling and selecting of previous date and month?

enter image description here

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Jayprakash Singh
  • 1,343
  • 3
  • 15
  • 28

1 Answers1

0

Use this to set minimum and maximum date. You can change any component like Day, month, year.

Objective 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];

Swift

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
RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70
Nupur Gupta
  • 305
  • 1
  • 12