Hi there,
For my current project I'm using endDate as Date() (i.e. whatever today is - currently April 1), and startDate as 2 weeks before endDate. I'm noticing that the calendar getting generated starts on March 1 even though startDate is somewhere in mid-March and generateInDates is set to .off. Wondering if this is expected behavior? Are startDate and endDate intended to be month boundaries, or is it possible to generate a calendar that starts mid-month?
Below is my configureCalendar function:
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
let endDate = Date()
let startDate = endDate.subtract(2.weeks)
let parameters = ConfigurationParameters(startDate: startDate,
endDate: endDate,
numberOfRows: 2,
calendar: Calendar.current,
generateInDates: .off,
generateOutDates: .tillEndOfGrid,
firstDayOfWeek: .sunday)
return parameters
}
Yes, it is meant to be month boundaries.
If you want to restrict boundaries you can check the visibility of the cell you do not wish to cross, and then simply scroll back.
Thanks for the reply. Can I ask what you mean by "check the visibility of the cell you do not wish to cross, and then simply scroll back"? Do you mean to hide the cells (e.g. isHidden = true or alpha = 0)? I'm confused about the "scroll back" part.
You know when you make a mental note to respond, and then forget to respond?
My bad.
I'll will provide an example for how you can do this over this weekend.
Much appreciated!
Here is an example of implementing a boundary on a 6-row calendar.
With this code, the user is not allowed to cross the month of august.
Override this function in your viewController
func scrollDidEndDecelerating(for calendar: JTAppleCalendarView) {
let visibleDates = calendarView.visibleDates()
let dateWeShouldNotCross = formatter.date(from: "2017 08 07")!
let dateToScrollBackTo = formatter.date(from: "2017 07 03")!
if visibleDates.monthDates.contains (where: {$0.date >= dateWeShouldNotCross}) {
calendarView.scrollToDate(dateToScrollBackTo)
return
}
}
Cool, thank you!
@zhanswift what did you do to get that error?
Please lets try to keep the questions developer friendly :D
@zhanswift ok. which version of the calendar are you using?
Thank you. Already solved.
Most helpful comment
Here is an example of implementing a boundary on a 6-row calendar.
With this code, the user is not allowed to cross the month of august.
Override this function in your viewController