Search code examples
iosswiftfscalendar

Disable future dates selection in FScalendar swift


I am using https://github.com/WenchaoD/FSCalendar in my project . MaximumSelectedDate is a read-only property .Then how can disable future dates ?


Solution

  • A workaround could be to edit FSCalendar method file. First make a bool variable, say isAllowedToLimitFutureDates and a string variable maxValidFutureDateAsString then change line 172 of this link to:

     if(!isAllowedToLimitFutureDates)
     {
         _maximumDate = [self.formatter dateFromString:@"2099-12-31"];
     }
     else
     {
         _maximumDate = maxValidFutureDateAsString; // say "2017-03-13"
     }
    

    So when you want to limit the dates set isAllowedToLimitFutureDates = true.

    Similar approach to line 1707.

    In case you cannot edit file and used PODs, then you can customize this control and override them.

    Hope that helps!