Skip to content
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
19 changes: 19 additions & 0 deletions CalendarDemo/MonthViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ - (void)viewDidLoad
{
[super viewDidLoad];
//self.monthPlannerView.dateFormat = @"dd MMM\nYYYY";

self.monthPlannerView.allowCustomDayBackgroundColor = YES;
}

#pragma mark - MGCMonthPlannerViewController
Expand Down Expand Up @@ -75,6 +77,23 @@ - (NSAttributedString*)monthPlannerView:(MGCMonthPlannerView *)view attributedSt
return attrStr;
}

- (UIColor*)monthPlannerView:(MGCMonthPlannerView*)view colorForDayCellAtDate:(NSDate*)date
{
NSDateComponents *component = [self.calendar components:NSCalendarUnitWeekday fromDate:date];
NSInteger weekday = [component weekday];

if ([self.calendar isDateInWeekend:date]) {
return view.weekendDayBackgroundColor;
} else {
if (weekday % 2 == 0) {
return [UIColor grayColor];
} else {
return [UIColor whiteColor];
}
}
}


#pragma mark - CalendarViewControllerNavigation

- (NSDate*)centerDate
Expand Down
6 changes: 4 additions & 2 deletions CalendarLib/MGCDayPlannerEKViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ - (MGCEventView*)dayPlannerView:(MGCDayPlannerView*)view viewForEventOfType:(MGC
evCell.font = [UIFont systemFontOfSize:11];
evCell.title = ev.title;
evCell.subtitle = ev.location;
evCell.color = [UIColor colorWithCGColor:ev.calendar.CGColor];
evCell.eventNormalBackgroundColor = [UIColor colorWithCGColor:ev.calendar.CGColor];
evCell.eventSelectedBackgroundColor = [UIColor colorWithCGColor:ev.calendar.CGColor];
evCell.style = MGCStandardEventViewStylePlain|MGCStandardEventViewStyleSubtitle;
evCell.style |= (type == MGCAllDayEventType) ?: MGCStandardEventViewStyleBorder;
return evCell;
Expand Down Expand Up @@ -424,7 +425,8 @@ - (MGCEventView*)dayPlannerView:(MGCDayPlannerView*)view viewForNewEventOfType:(

MGCStandardEventView *evCell = [MGCStandardEventView new];
evCell.title = NSLocalizedString(@"New Event", nil);
evCell.color = [UIColor colorWithCGColor:defaultCalendar.CGColor];
evCell.eventNormalBackgroundColor = [UIColor colorWithCGColor:defaultCalendar.CGColor];
evCell.eventSelectedBackgroundColor = [UIColor colorWithCGColor:defaultCalendar.CGColor];
return evCell;
}

Expand Down
6 changes: 4 additions & 2 deletions CalendarLib/MGCMonthPlannerEKViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ - (MGCEventView*)monthPlannerView:(MGCMonthPlannerView*)view cellForEventAtIndex
evCell.title = ev.title;
evCell.subtitle = ev.location;
evCell.detail = [self.dateFormatter stringFromDate:ev.startDate];
evCell.color = [UIColor colorWithCGColor:ev.calendar.CGColor];
evCell.eventNormalBackgroundColor = [UIColor colorWithCGColor:ev.calendar.CGColor];
evCell.eventSelectedBackgroundColor = [UIColor colorWithCGColor:ev.calendar.CGColor];

NSDate *start = [self.calendar mgc_startOfDayForDate:ev.startDate];
NSDate *end = [self.calendar mgc_nextStartOfDayForDate:ev.endDate];
Expand All @@ -416,7 +417,8 @@ - (MGCEventView*)monthPlannerView:(MGCMonthPlannerView*)view cellForNewEventAtDa

MGCStandardEventView *evCell = [MGCStandardEventView new];
evCell.title = NSLocalizedString(@"New Event", nil);
evCell.color = [UIColor colorWithCGColor:defaultCalendar.CGColor];
evCell.eventNormalBackgroundColor = [UIColor colorWithCGColor:defaultCalendar.CGColor];
evCell.eventSelectedBackgroundColor = [UIColor colorWithCGColor:defaultCalendar.CGColor];
return evCell;
}

Expand Down
14 changes: 14 additions & 0 deletions CalendarLib/MGCMonthPlannerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ typedef NS_ENUM(NSUInteger, MGCMonthPlannerScrollAlignment) {
*/
@property (nonatomic) BOOL canMoveEvents;

/*!
@abstract Determines whether an day can have different background color.
@discussion The default value is NO.
*/
@property (nonatomic) BOOL allowCustomDayBackgroundColor;

/*!
@abstract The object that provides the data for the month planner view
@discussion The data source must adopt the `MGCMonthPlannerViewDataSource` protocol.
Expand Down Expand Up @@ -463,6 +469,14 @@ typedef NS_ENUM(NSUInteger, MGCMonthPlannerScrollAlignment) {
*/
- (BOOL)monthPlannerView:(MGCMonthPlannerView*)view canMoveCellForEventAtIndex:(NSUInteger)index date:(NSDate*)date;

/*!
@abstract Asks the data source for the color that corresponds to the specified date in the month planner view.
@discussion This method is not called when allowCustomDayBackgroundColor property is set to NO.

*/
- (UIColor*)monthPlannerView:(MGCMonthPlannerView*)view colorForDayCellAtDate:(NSDate*)date;


@end

/*!
Expand Down
5 changes: 5 additions & 0 deletions CalendarLib/MGCMonthPlannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ - (void)setup
_selectedEventDate = nil;
_canCreateEvents = YES;
_canMoveEvents = YES;
_allowCustomDayBackgroundColor = NO;
_calendarBackgroundColor = [UIColor whiteColor];
_weekDayBackgroundColor = [UIColor whiteColor];
_weekendDayBackgroundColor = [UIColor colorWithWhite:.97 alpha:.8];
Expand Down Expand Up @@ -1399,6 +1400,10 @@ - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellFo
cell.dayLabel.attributedText = attrStr;
cell.backgroundColor = [self.calendar isDateInWeekend:date] ? self.weekendDayBackgroundColor : self.weekDayBackgroundColor;

if ([self.dataSource respondsToSelector:@selector(monthPlannerView:colorForDayCellAtDate:)] && self.allowCustomDayBackgroundColor) {
cell.backgroundColor = [self.dataSource monthPlannerView:self colorForDayCellAtDate:date];
}

if (self.style & MGCMonthPlannerStyleDots) {
NSUInteger eventsCounts = [self.dataSource monthPlannerView:self numberOfEventsAtDate:date];
cell.showsDot = eventsCounts > 0;
Expand Down
10 changes: 8 additions & 2 deletions CalendarLib/MGCStandardEventView.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ typedef NS_OPTIONS(NSUInteger, MGCStandardEventViewStyle) {
/*! Detail - displayed with a smaller font and right aligned. */
@property (nonatomic, copy) NSString *detail;

/*! The color is used for background or text, depending on the style. */
@property (nonatomic) UIColor *color;
/*! The color is used for text, depending on the style. */
@property (nonatomic) UIColor *textColor;

/*! The color is used for background, depending on the style. */
@property (nonatomic) UIColor *eventNormalBackgroundColor;

/*! The color is used for selected background, depending on the style. */
@property (nonatomic) UIColor *eventSelectedBackgroundColor;

/*! Style of the view. */
@property (nonatomic) MGCStandardEventViewStyle style;
Expand Down
18 changes: 11 additions & 7 deletions CalendarLib/MGCStandardEventView.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ - (instancetype)initWithFrame:(CGRect)frame
if (self = [super initWithFrame:frame]) {
self.contentMode = UIViewContentModeRedraw;

_color = [UIColor blackColor];
_textColor = [UIColor blackColor];
_eventNormalBackgroundColor = [UIColor lightGrayColor];
_eventSelectedBackgroundColor = [UIColor grayColor];
_style = MGCStandardEventViewStylePlain|MGCStandardEventViewStyleSubtitle;
_font = [UIFont systemFontOfSize:[UIFont smallSystemFontSize]];
_leftBorderView = [[UIView alloc]initWithFrame:CGRectNull];
Expand Down Expand Up @@ -94,7 +96,7 @@ - (void)redrawStringInRect:(CGRect)rect
//style.lineBreakMode = NSLineBreakByTruncatingMiddle;
[as addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, as.length)];

UIColor *color = self.selected ? [UIColor whiteColor] : self.color;
UIColor *color = self.selected ? [UIColor whiteColor] : self.textColor;
[as addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, as.length)];

self.attrString = as;
Expand All @@ -110,7 +112,7 @@ - (void)layoutSubviews

- (void)setColor:(UIColor*)color
{
_color = color;
_textColor = color;
[self resetColors];
}

Expand All @@ -123,12 +125,12 @@ - (void)setStyle:(MGCStandardEventViewStyle)style

- (void)resetColors
{
self.leftBorderView.backgroundColor = self.color;
self.leftBorderView.backgroundColor = self.textColor;

if (self.selected)
self.backgroundColor = self.selected ? self.color : [self.color colorWithAlphaComponent:.3];
self.backgroundColor = self.selected ? self.eventSelectedBackgroundColor : self.eventNormalBackgroundColor;
else if (self.style & MGCStandardEventViewStylePlain)
self.backgroundColor = [self.color colorWithAlphaComponent:.3];
self.backgroundColor = self.eventNormalBackgroundColor;
else
self.backgroundColor = [UIColor clearColor];

Expand Down Expand Up @@ -181,7 +183,9 @@ - (id)copyWithZone:(NSZone *)zone
cell.title = self.title;
cell.subtitle = self.subtitle;
cell.detail = self.detail;
cell.color = self.color;
cell.textColor = self.textColor;
cell.eventNormalBackgroundColor = self.eventNormalBackgroundColor;
cell.eventSelectedBackgroundColor = self.eventSelectedBackgroundColor;
cell.style = self.style;

return cell;
Expand Down