I am using https://github.com/WenchaoD/FSCalendar in my project . MaximumSelectedDate is a read-only property .Then how can disable future dates ?
问题:
回答1:
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!
回答2:
You should be using the delegate method to address this
func maximumDate(for calendar: FSCalendar) -> Date {
return Date()
}
回答3:
@Devraj answer is correct, there are delegates for both minimum and maximum dates, all you need to do is implementing the proper one (the later one in your case) in the controller that's conforming to FSCalendarDelegate
and that'll do the trick.
func maximumDateForCalendar(calendar: FSCalendar) -> NSDate {
return NSDate() // NSDate of your choosing here
}
回答4:
for Swift 3
fileprivate lazy var dateFormatter2: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "dd-MM-yyyy"
return formatter }()
let today = dateFormatter2.string(from: calendar.selectedDate!)
let dateObj = dateFormatter2.date(from: today)
if dateObj! > calendar.today! {
// Your logic here
}