@@ -11,51 +11,69 @@ import UIKit
11
11
private let reuseIdentifier = " Cell "
12
12
13
13
@objc public protocol EPCalendarPickerDelegate {
14
-
15
14
optional func epCalendarPicker( _: EPCalendarPicker , didCancel error : NSError )
16
15
optional func epCalendarPicker( _: EPCalendarPicker , didSelectDate date : NSDate )
17
16
optional func epCalendarPicker( _: EPCalendarPicker , didSelectMultipleDate dates : [ NSDate ] )
18
-
19
17
}
20
18
21
-
22
19
public class EPCalendarPicker : UICollectionViewController {
23
20
24
21
public var calendarDelegate : EPCalendarPickerDelegate ?
25
22
public var multiSelectEnabled : Bool
26
23
public var showsTodaysButton : Bool = true
27
24
private var arrSelectedDates = [ NSDate] ( )
28
25
public var tintColor : UIColor
26
+
27
+ public var dayDisabledTintColor : UIColor
29
28
public var weekdayTintColor : UIColor
30
29
public var weekendTintColor : UIColor
31
30
public var todayTintColor : UIColor
32
31
public var dateSelectionColor : UIColor
33
32
public var monthTitleColor : UIColor
34
33
34
+ // new options
35
+ public var startDate : NSDate ?
36
+ public var hightlightsToday : Bool = true
37
+ public var hideDaysFromOtherMonth : Bool = false
38
+ public var barTintColor : UIColor
39
+
40
+ public var backgroundImage : UIImage ?
41
+ public var backgroundColor : UIColor ?
35
42
36
43
private( set) public var startYear : Int
37
44
private( set) public var endYear : Int
38
45
39
46
override public func viewDidLoad( ) {
40
47
super. viewDidLoad ( )
41
- self . title = " Date Picker "
42
- self . collectionView? . delegate = self
43
- self . collectionView? . backgroundColor = UIColor . whiteColor ( )
48
+
49
+ // setup Navigationbar
44
50
self . navigationController? . navigationBar. tintColor = self . tintColor
51
+ self . navigationController? . navigationBar. barTintColor = self . barTintColor
52
+ self . navigationController? . navigationBar. titleTextAttributes = [ NSForegroundColorAttributeName: self . tintColor]
53
+
54
+ // setup collectionview
55
+ self . collectionView? . delegate = self
56
+ self . collectionView? . backgroundColor = UIColor . clearColor ( )
45
57
self . collectionView? . showsHorizontalScrollIndicator = false
46
58
self . collectionView? . showsVerticalScrollIndicator = false
47
59
48
-
49
60
// Register cell classes
50
61
self . collectionView!. registerNib ( UINib ( nibName: " EPCalendarCell1 " , bundle: NSBundle ( forClass: EPCalendarPicker . self ) ) , forCellWithReuseIdentifier: reuseIdentifier)
62
+ self . collectionView!. registerNib ( UINib ( nibName: " EPCalendarHeaderView " , bundle: NSBundle ( forClass: EPCalendarPicker . self ) ) , forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: " Header " )
51
63
52
- self . collectionView!. registerNib ( UINib ( nibName: " EPCalendarHeaderView " , bundle: NSBundle ( forClass: EPCalendarPicker . self ) ) , forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: " Header " )
53
64
inititlizeBarButtons ( )
54
65
55
66
dispatch_async ( dispatch_get_main_queue ( ) ) { ( ) -> Void in
56
67
self . scrollToToday ( )
57
68
}
58
- // Do any additional setup after loading the view.
69
+
70
+ if backgroundImage != nil {
71
+ self . collectionView!. backgroundView = UIImageView ( image: backgroundImage)
72
+ } else if backgroundColor != nil {
73
+ self . collectionView? . backgroundColor = backgroundColor
74
+ } else {
75
+ self . collectionView? . backgroundColor = UIColor . whiteColor ( )
76
+ }
59
77
}
60
78
61
79
@@ -113,6 +131,8 @@ public class EPCalendarPicker: UICollectionViewController {
113
131
114
132
//Text color initializations
115
133
self . tintColor = EPDefaults . tintColor
134
+ self . barTintColor = EPDefaults . barTintColor
135
+ self . dayDisabledTintColor = EPDefaults . dayDisabledTintColor
116
136
self . weekdayTintColor = EPDefaults . weekdayTintColor
117
137
self . weekendTintColor = EPDefaults . weekendTintColor
118
138
self . dateSelectionColor = EPDefaults . dateSelectionColor
@@ -129,7 +149,6 @@ public class EPCalendarPicker: UICollectionViewController {
129
149
self . arrSelectedDates. appendContentsOf ( selectedDates!)
130
150
}
131
151
super. init ( collectionViewLayout: layout)
132
-
133
152
}
134
153
135
154
@@ -193,22 +212,37 @@ public class EPCalendarPicker: UICollectionViewController {
193
212
}
194
213
if ( currentDate > nextMonthFirstDay) {
195
214
cell. isCellSelectable = false
196
- cell. lblDay. textColor = EPColors . LightGrayColor
215
+ if hideDaysFromOtherMonth {
216
+ cell. lblDay. textColor = UIColor . clearColor ( )
217
+ } else {
218
+ cell. lblDay. textColor = self . dayDisabledTintColor
219
+ }
197
220
}
198
- if currentDate. isToday ( ) {
221
+ if currentDate. isToday ( ) && hightlightsToday {
199
222
cell. setTodayCellColor ( todayTintColor)
200
223
}
201
224
225
+ if startDate != nil {
226
+ if NSCalendar . currentCalendar ( ) . startOfDayForDate ( cell. currentDate) < NSCalendar . currentCalendar ( ) . startOfDayForDate ( startDate!) {
227
+ cell. isCellSelectable = false
228
+ cell. lblDay. textColor = self . dayDisabledTintColor
229
+ }
230
+ }
202
231
}
203
232
}
204
233
else {
205
234
cell. isCellSelectable = false
206
235
let previousDay = firstDayOfThisMonth. dateByAddingDays ( - ( prefixDays - indexPath. row) )
207
236
cell. currentDate = previousDay
208
237
cell. lblDay. text = " \( previousDay. day ( ) ) "
209
- cell. lblDay. textColor = EPColors . LightGrayColor
210
- cell. lblDay. layer. backgroundColor = UIColor . whiteColor ( ) . CGColor
238
+ if hideDaysFromOtherMonth {
239
+ cell. lblDay. textColor = UIColor . clearColor ( )
240
+ } else {
241
+ cell. lblDay. textColor = self . dayDisabledTintColor
242
+ }
211
243
}
244
+
245
+ cell. backgroundColor = UIColor . clearColor ( )
212
246
return cell
213
247
}
214
248
@@ -238,11 +272,12 @@ public class EPCalendarPicker: UICollectionViewController {
238
272
header. lblTitle. textColor = monthTitleColor
239
273
header. updateWeekdaysLabelColor ( weekdayTintColor)
240
274
header. updateWeekendLabelColor ( weekendTintColor)
275
+ header. backgroundColor = UIColor . clearColor ( )
276
+
241
277
return header;
242
278
}
243
279
244
280
return UICollectionReusableView ( )
245
-
246
281
}
247
282
248
283
override public func collectionView( collectionView: UICollectionView , didSelectItemAtIndexPath indexPath: NSIndexPath ) {
@@ -274,7 +309,7 @@ public class EPCalendarPicker: UICollectionViewController {
274
309
else {
275
310
cell. deSelectedForLabelColor ( weekdayTintColor)
276
311
}
277
- if cell. currentDate. isToday ( ) {
312
+ if cell. currentDate. isToday ( ) && hightlightsToday {
278
313
cell. setTodayCellColor ( todayTintColor)
279
314
}
280
315
}
0 commit comments