Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge #74

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions KDCalendar/CalendarView/CalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ public protocol CalendarViewDelegate {
/* optional */
func calendar(_ calendar : CalendarView, canSelectDate date : Date) -> Bool
func calendar(_ calendar : CalendarView, didDeselectDate date : Date) -> Void
func calendar(_ calendar : CalendarView, didLongPressDate date : Date) -> Void
func calendar(_ calendar : CalendarView, didLongPressDate date : Date, withEvents events: [CalendarEvent]?) -> Void
}

extension CalendarViewDelegate {
func calendar(_ calendar : CalendarView, canSelectDate date : Date) -> Bool { return true }
func calendar(_ calendar : CalendarView, didDeselectDate date : Date) -> Void { return }
func calendar(_ calendar : CalendarView, didLongPressDate date : Date) -> Void { return }
func calendar(_ calendar : CalendarView, didLongPressDate date : Date, withEvents events: [CalendarEvent]?) -> Void { return }
}

public class CalendarView: UIView {
Expand Down Expand Up @@ -227,7 +227,14 @@ public class CalendarView: UIView {
return
}

self.delegate?.calendar(self, didLongPressDate: date)
guard
let indexPathEvents = collectionView.indexPathForItem(at: point),
let events = self.eventsByIndexPath[indexPathEvents], events.count > 0 else {
self.delegate?.calendar(self, didLongPressDate: date, withEvents: nil)
return
}

self.delegate?.calendar(self, didLongPressDate: date, withEvents: events)
}

override open func layoutSubviews() {
Expand Down
8 changes: 7 additions & 1 deletion KDCalendar/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ class ViewController: UIViewController, CalendarViewDataSource, CalendarViewDele
}


func calendar(_ calendar: CalendarView, didLongPressDate date : Date) {
func calendar(_ calendar: CalendarView, didLongPressDate date : Date, withEvents events: [CalendarEvent]?) {

if let events = events {
for event in events {
print("\t\"\(event.title)\" - Starting at:\(event.startDate)")
}
}

let alert = UIAlertController(title: "Create New Event", message: "Message", preferredStyle: .alert)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Set the locale for header labels of Weekdays and Month. Use:
CalendarView.Style.locale = Locale(identifier: "en_US")
```

![IB Screenshot](https://github.com/mmick66/CalendarView/blob/Fix-Issue-%2355/Assets/locale.png)
![IB Screenshot](https://github.com/mmick66/CalendarView/blob/master/Assets/locale.png)

The locale default is Locale.current of your device.

Expand Down