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

Multiple selection and custom cell feature #89

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions PDTSimpleCalendar/PDTSimpleCalendarViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
24 changes: 20 additions & 4 deletions PDTSimpleCalendar/PDTSimpleCalendarViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down