-
Notifications
You must be signed in to change notification settings - Fork 0
/
CollectionViewCell.swift
executable file
·108 lines (75 loc) · 3.25 KB
/
CollectionViewCell.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Cellule.swift
// CalendarScroll
//
// Created by Daniel Lahoz on 29/6/16.
// Copyright © 2016 Lahoz. All rights reserved.
//
import UIKit
class CollectionViewCell: UICollectionViewCell {
var monthNumber = 0
@IBOutlet weak var cellCollectioView: UICollectionView!
@IBOutlet weak var monthLabel: UILabel!
var previusdays = [Date]()
var monthdays = [Date]()
var month = Date(){
didSet {
(previusdays, monthdays) = month.getDaysOfTheMonth()
monthNumber = previusdays.count + monthdays.count
self.cellCollectioView.reloadData()
}
}
override func prepareForReuse() {
monthLabel.text = ""
monthNumber = 0
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
//MARK: - COLLECTION VIEW DATA SOURCE PREFECTCHING
extension CollectionViewCell: UICollectionViewDataSourcePrefetching{
func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
//Precached stuff
}
}
//MARK: - COLLECTION VIEW DATA SOURCE
extension CollectionViewCell : UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let smallCell = collectionView.dequeueReusableCell(withReuseIdentifier: "dayCell", for: indexPath) as! DayCollectionViewCell
if (indexPath as NSIndexPath).item < previusdays.count {
smallCell.numberLabel.text = previusdays[(indexPath as NSIndexPath).item].getTextDay()
smallCell.alpha = 0.4
}else{
smallCell.numberLabel.text = monthdays[(indexPath as NSIndexPath).item - previusdays.count].getTextDay()
smallCell.alpha = 1.0
}
return smallCell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return monthNumber
}
}
//MARK: - COLLECTION VIEW FLOW
extension CollectionViewCell : UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 1
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
var rows = CGFloat(trunc( Float(monthNumber) / 7))
if monthNumber % 7 != 0 {
rows = rows + 1
}
//print("\(monthLabel.text) \(monthNumber) \(rows)")
return CGSize(width: collectionView.frame.size.width/7 - 1, height:collectionView.frame.size.height/rows - 1)
}
}
//MARK: - COLLECTION VIEW DELEGATE
extension CollectionViewCell : UICollectionViewDelegate{
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//Do stuff...
}
}