richardtop / CalendarKit

📅 Calendar for Apple platforms in Swift
https://www.youtube.com/watch?v=cJ63-_z1qg8
MIT License
2.49k stars 334 forks source link

Week Change delegate? #269

Closed BBITSDev closed 3 years ago

BBITSDev commented 3 years ago

New Issue Checklist

Result I am trying to achieve

I am trying to capture Week Change event when user either swipe the top label or swipe timelineview. Is there any delegate method to detect Week change?

Thanks in advance.

richardtop commented 3 years ago

Please, use the following methods:

  override func dayView(dayView: DayView, willMoveTo date: Date) {
    print("DayView = \(dayView) will move to: \(date)")
  }

  override func dayView(dayView: DayView, didMoveTo date: Date) {
    print("DayView = \(dayView) did move to: \(date)")
  }

By checking whether the new date is in a different week than the previous one, you'll be able to generate the Week Change event.

  1. Store the initial date in a variable
  2. Get the new date using override func dayView(dayView: DayView, didMoveTo date: Date) { method
  3. Compare the two dates using e.g. NSCalendar methods or DateTools library. if they're in a different week, then the week has changed.
  4. Store the new date in a variable, repeat this as many times as user changes the date.

Please, close this issue if your problem has been resolved.

BBITSDev commented 3 years ago

Appreciate quick response.

richardtop commented 3 years ago

@BBITSDev do you have any more questions on this topic? If you've resolved this issue, please, close the ticket.