forked from zjfjack/JZCalendarWeekView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LongPressWeekView.swift
53 lines (45 loc) · 2.38 KB
/
LongPressWeekView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// LongPressWeekView.swift
// JZCalendarWeekViewExample
//
// Created by Jeff Zhang on 30/4/18.
// Copyright © 2018 Jeff Zhang. All rights reserved.
//
import UIKit
import JZCalendarWeekView
/// All-Day & Long Press
class LongPressWeekView: JZLongPressWeekView {
override func registerViewClasses() {
super.registerViewClasses()
self.collectionView.register(UINib(nibName: LongPressEventCell.className, bundle: nil), forCellWithReuseIdentifier: LongPressEventCell.className)
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: LongPressEventCell.className, for: indexPath) as! LongPressEventCell
cell.configureCell(event: getCurrentEvent(with: indexPath) as! AllDayEvent)
return cell
}
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == JZSupplementaryViewKinds.allDayHeader {
let alldayHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: kind, for: indexPath) as! JZAllDayHeader
let date = flowLayout.dateForColumnHeader(at: indexPath)
let events = allDayEventsBySection[date]
let views = getAllDayHeaderViews(allDayEvents: events as? [AllDayEvent] ?? [])
alldayHeader.updateView(views: views)
return alldayHeader
}
return super.collectionView(collectionView, viewForSupplementaryElementOfKind: kind, at: indexPath)
}
private func getAllDayHeaderViews(allDayEvents: [AllDayEvent]) -> [UIView] {
var allDayViews = [UIView]()
for event in allDayEvents {
let view = UINib(nibName: LongPressEventCell.className, bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! LongPressEventCell
view.configureCell(event: event, isAllDay: true)
allDayViews.append(view)
}
return allDayViews
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedEvent = getCurrentEvent(with: indexPath) as! AllDayEvent
ToastUtil.toastMessageInTheMiddle(message: selectedEvent.title)
}
}