From fe71a47df0a196b55ae9e0556c06602446342348 Mon Sep 17 00:00:00 2001 From: Arnaud Lays Date: Mon, 11 Jul 2016 15:22:36 -0400 Subject: [PATCH 1/3] Initialize startDate for week planner at the beginning of current week --- CalendarLib/MGCDayPlannerView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CalendarLib/MGCDayPlannerView.m b/CalendarLib/MGCDayPlannerView.m index a7a276c6..6e92fb5a 100755 --- a/CalendarLib/MGCDayPlannerView.m +++ b/CalendarLib/MGCDayPlannerView.m @@ -439,7 +439,7 @@ - (void)setEventIndicatorDotColor:(UIColor *)eventIndicatorDotColor - (NSDate*)startDate { if (_startDate == nil) { - _startDate = [self.calendar mgc_startOfDayForDate:[NSDate date]]; + _startDate = [self.calendar mgc_startOfWeekForDate:[NSDate date]]; if (self.dateRange && ![self.dateRange containsDate:_startDate]) { _startDate = self.dateRange.start; From 4ec6e3fd7860710766ee5ec38a411654524c09cb Mon Sep 17 00:00:00 2001 From: Arnaud Lays Date: Mon, 11 Jul 2016 15:22:46 -0400 Subject: [PATCH 2/3] Can change background color of selected day (monthplannerview) --- CalendarLib/MGCMonthPlannerView.h | 7 +++++++ CalendarLib/MGCMonthPlannerView.m | 25 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CalendarLib/MGCMonthPlannerView.h b/CalendarLib/MGCMonthPlannerView.h index febd05da..8162f3f5 100755 --- a/CalendarLib/MGCMonthPlannerView.h +++ b/CalendarLib/MGCMonthPlannerView.h @@ -177,6 +177,12 @@ typedef NS_ENUM(NSUInteger, MGCMonthPlannerScrollAlignment) { */ @property (nonatomic, strong) UIColor *weekendDayBackgroundColor; +/*! + @abstract Background color for selected day cell. + @discussion The default color is none. + */ +@property (nonatomic, strong) UIColor *selectedDayBackgroundColor; + /*! @abstract Text color for the weekday headers on the top of the view. @discussion The default color is black. @@ -242,6 +248,7 @@ typedef NS_ENUM(NSUInteger, MGCMonthPlannerScrollAlignment) { */ @property (nonatomic, copy) MGCDateRange *dateRange; +@property (nonatomic, copy) NSDate *daySelected; /*! @group Creating event views diff --git a/CalendarLib/MGCMonthPlannerView.m b/CalendarLib/MGCMonthPlannerView.m index 5e3dff4a..56bc743b 100755 --- a/CalendarLib/MGCMonthPlannerView.m +++ b/CalendarLib/MGCMonthPlannerView.m @@ -774,6 +774,22 @@ - (void)selectEventCellAtIndex:(NSUInteger)index date:(NSDate*)date } } +// public +- (void)setDaySelected:(NSDate *)daySelected { + NSDate *dayToDeselect = [_daySelected copy]; + _daySelected = daySelected; + + [self reloadItemForDate:dayToDeselect]; + [self reloadItemForDate:daySelected]; +} + +- (void)reloadItemForDate:(NSDate *)date { + NSIndexPath *indexPath = [self indexPathForDate:date]; + if (indexPath) { + [self.eventsView reloadItemsAtIndexPaths:@[indexPath]]; + } +} + #pragma mark - Scrolling // public - deprecated @@ -1397,7 +1413,13 @@ - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellFo } cell.dayLabel.attributedText = attrStr; - cell.backgroundColor = [self.calendar isDateInWeekend:date] ? self.weekendDayBackgroundColor : self.weekDayBackgroundColor; + if (self.selectedDayBackgroundColor && [self.calendar mgc_isDate:date sameDayAsDate:self.daySelected]) { + cell.selected = YES; + cell.backgroundColor = self.selectedDayBackgroundColor; + } else { + cell.selected = NO; + cell.backgroundColor = [self.calendar isDateInWeekend:date] ? self.weekendDayBackgroundColor : self.weekDayBackgroundColor; + } if (self.style & MGCMonthPlannerStyleDots) { NSUInteger eventsCounts = [self.dataSource monthPlannerView:self numberOfEventsAtDate:date]; @@ -1617,6 +1639,7 @@ - (void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPat { if ([self.delegate respondsToSelector:@selector(monthPlannerView:didSelectDayCellAtDate:)]) { NSDate *date = [self dateForDayAtIndexPath:indexPath]; + self.daySelected = date; [self.delegate monthPlannerView:self didSelectDayCellAtDate:date]; } From c3c91e83fc2214950c63df688e51fb1193daae36 Mon Sep 17 00:00:00 2001 From: Arnaud Lays Date: Mon, 11 Jul 2016 15:57:47 -0400 Subject: [PATCH 3/3] Dot color when day selected --- CalendarLib/MGCMonthPlannerView.h | 5 +++++ CalendarLib/MGCMonthPlannerView.m | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CalendarLib/MGCMonthPlannerView.h b/CalendarLib/MGCMonthPlannerView.h index 8162f3f5..be05169b 100755 --- a/CalendarLib/MGCMonthPlannerView.h +++ b/CalendarLib/MGCMonthPlannerView.h @@ -138,6 +138,11 @@ typedef NS_ENUM(NSUInteger, MGCMonthPlannerScrollAlignment) { */ @property (nonatomic) UIColor *eventsDotColor; +/*! + @abstract Returns the color of the dot displayed when the month planner view style is set to MGCMonthPlannerStyleDots & the day is selected + */ +@property (nonatomic) UIColor *eventsDaySelectedDotColor; + /*! @abstract Returns the style of the months' background grid. @discussion If MGCMonthPlannerGridStyleFill is set, the view fills the grid for the first and last week of the month, and the month header, if displayed, is center-aligned. diff --git a/CalendarLib/MGCMonthPlannerView.m b/CalendarLib/MGCMonthPlannerView.m index 56bc743b..a6af4d28 100755 --- a/CalendarLib/MGCMonthPlannerView.m +++ b/CalendarLib/MGCMonthPlannerView.m @@ -1413,9 +1413,12 @@ - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellFo } cell.dayLabel.attributedText = attrStr; + + UIColor *dotColor = self.eventsDotColor; if (self.selectedDayBackgroundColor && [self.calendar mgc_isDate:date sameDayAsDate:self.daySelected]) { cell.selected = YES; cell.backgroundColor = self.selectedDayBackgroundColor; + dotColor = self.eventsDaySelectedDotColor ? : dotColor; } else { cell.selected = NO; cell.backgroundColor = [self.calendar isDateInWeekend:date] ? self.weekendDayBackgroundColor : self.weekDayBackgroundColor; @@ -1424,7 +1427,7 @@ - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellFo if (self.style & MGCMonthPlannerStyleDots) { NSUInteger eventsCounts = [self.dataSource monthPlannerView:self numberOfEventsAtDate:date]; cell.showsDot = eventsCounts > 0; - cell.dotColor = self.eventsDotColor; + cell.dotColor = dotColor; } return cell; }