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

Can select day in monthPlannerView #36

Open
wants to merge 3 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CalendarLib/MGCDayPlannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions CalendarLib/MGCMonthPlannerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -177,6 +182,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.
Expand Down Expand Up @@ -242,6 +253,7 @@ typedef NS_ENUM(NSUInteger, MGCMonthPlannerScrollAlignment) {
*/
@property (nonatomic, copy) MGCDateRange *dateRange;

@property (nonatomic, copy) NSDate *daySelected;

/*!
@group Creating event views
Expand Down
30 changes: 28 additions & 2 deletions CalendarLib/MGCMonthPlannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1397,12 +1413,21 @@ - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellFo
}

cell.dayLabel.attributedText = attrStr;
cell.backgroundColor = [self.calendar isDateInWeekend:date] ? self.weekendDayBackgroundColor : self.weekDayBackgroundColor;

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;
}

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;
}
Expand Down Expand Up @@ -1617,6 +1642,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];
}

Expand Down