diff --git a/PDTSimpleCalendar/PDTSimpleCalendarViewController.h b/PDTSimpleCalendar/PDTSimpleCalendarViewController.h index 661e056..ee5943c 100644 --- a/PDTSimpleCalendar/PDTSimpleCalendarViewController.h +++ b/PDTSimpleCalendar/PDTSimpleCalendarViewController.h @@ -154,4 +154,23 @@ */ - (UIColor *)simpleCalendarViewController:(PDTSimpleCalendarViewController *)controller textColorForDate:(NSDate *)date; +/** @name Date cell Customization */ + +/** + * Asks the delegate custom date cell + * + * @return Customized date cell should be inherited from `PSTSimpleCalenderViewCell` + */ +- (Class)customCollectionViewCellClass; + +/** + * Give delegate a chance to manipulate custom date cell + * + * @param cell the calendarView cell + * @param date the date of cell + * + * @return YES if the calendar must ask the delegate for text and circle color, NO if it should use default values. + */ +- (void)customCellManipulate:(UICollectionViewCell * __nonnull)cell withDate:( NSDate * _Nullable )date; + @end; diff --git a/PDTSimpleCalendar/PDTSimpleCalendarViewController.m b/PDTSimpleCalendar/PDTSimpleCalendarViewController.m index 658e711..b7e8d2e 100644 --- a/PDTSimpleCalendar/PDTSimpleCalendarViewController.m +++ b/PDTSimpleCalendar/PDTSimpleCalendarViewController.m @@ -206,9 +206,11 @@ - (void)setSelectedDate:(NSDate *)newSelectedDate return; } - - [[self cellForItemAtDate:_selectedDate] setSelected:NO]; - [[self cellForItemAtDate:startOfDay] setSelected:YES]; + // Don't clear other cell circle if collectionView in multipleSelection mode + if (!self.collectionView.allowsMultipleSelection) { + [[self cellForItemAtDate:_selectedDate] setSelected:NO]; + [[self cellForItemAtDate:startOfDay] setSelected:YES]; + } _selectedDate = startOfDay; @@ -271,7 +273,15 @@ - (void)viewDidLoad // Do any additional setup after loading the view. //Configure the Collection View - [self.collectionView registerClass:[PDTSimpleCalendarViewCell class] forCellWithReuseIdentifier:PDTSimpleCalendarViewCellIdentifier]; + Class collectionViewCellClass; + // if delegate offer a custom cell + if ([self.delegate respondsToSelector:@selector(customCollectionViewCellClass)]) { + collectionViewCellClass = [self.delegate customCollectionViewCellClass]; // use it + } + else { + collectionViewCellClass = [PDTSimpleCalendarViewCell class]; // otherwise use default cell + } + [self.collectionView registerClass:collectionViewCellClass forCellWithReuseIdentifier:PDTSimpleCalendarViewCellIdentifier]; [self.collectionView registerClass:[PDTSimpleCalendarViewHeader class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:PDTSimpleCalendarViewHeaderIdentifier]; self.collectionView.delegate = self; @@ -399,6 +409,12 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell if (![self isEnabledDate:cellDate] || isCustomDate) { [cell refreshCellColors]; } + + // let delegate manipulate cell + if ([self.delegate respondsToSelector:@selector(customCellManipulate:withDate:)]) { + BOOL hasDate = cellDateComponents.month == firstOfMonthsComponents.month; + [self.delegate customCellManipulate:cell withDate:hasDate ? cellDate : nil]; + } //We rasterize the cell for performances purposes. //The circle background is made using roundedCorner which is a super expensive operation, specially with a lot of items on the screen to display (like we do)