diff --git a/Example/DelegateAppearanceViewController.h b/Example/DelegateAppearanceViewController.h index d4f0857..050e3bf 100644 --- a/Example/DelegateAppearanceViewController.h +++ b/Example/DelegateAppearanceViewController.h @@ -13,7 +13,8 @@ @property (weak, nonatomic) FSCalendar *calendar; -@property (strong, nonatomic) NSDictionary *selectionColors; +@property (strong, nonatomic) NSDictionary *fillSelectionColors; +@property (strong, nonatomic) NSDictionary *fillDefaultColors; @property (strong, nonatomic) NSDictionary *borderDefaultColors; @property (strong, nonatomic) NSDictionary *borderSelectionColors; diff --git a/Example/DelegateAppearanceViewController.m b/Example/DelegateAppearanceViewController.m index f09974d..bf33b96 100644 --- a/Example/DelegateAppearanceViewController.m +++ b/Example/DelegateAppearanceViewController.m @@ -20,41 +20,54 @@ if (self) { self.title = @"FSCalendar"; - self.selectionColors = @{@"2015/10/8":[UIColor greenColor], - @"2015/10/6":[UIColor purpleColor], + self.fillDefaultColors = @{@"2015/10/08":[UIColor purpleColor], + @"2015/10/06":[UIColor greenColor], + @"2015/10/18":[UIColor cyanColor], + @"2015/10/22":[UIColor yellowColor], + @"2015/11/08":[UIColor purpleColor], + @"2015/11/06":[UIColor greenColor], + @"2015/11/18":[UIColor cyanColor], + @"2015/11/22":[UIColor yellowColor], + @"2015/12/08":[UIColor purpleColor], + @"2015/12/06":[UIColor greenColor], + @"2015/12/18":[UIColor cyanColor], + @"2015/12/22":[UIColor magentaColor]}; + + self.fillSelectionColors = @{@"2015/10/08":[UIColor greenColor], + @"2015/10/06":[UIColor purpleColor], @"2015/10/17":[UIColor grayColor], @"2015/10/21":[UIColor cyanColor], - @"2015/11/8":[UIColor greenColor], - @"2015/11/6":[UIColor purpleColor], + @"2015/11/08":[UIColor greenColor], + @"2015/11/06":[UIColor purpleColor], @"2015/11/17":[UIColor grayColor], @"2015/11/21":[UIColor cyanColor], - @"2015/12/8":[UIColor greenColor], - @"2015/12/6":[UIColor purpleColor], + @"2015/12/08":[UIColor greenColor], + @"2015/12/06":[UIColor purpleColor], @"2015/12/17":[UIColor grayColor], @"2015/12/21":[UIColor cyanColor]}; - self.borderDefaultColors = @{@"2015/10/8":[UIColor brownColor], + self.borderDefaultColors = @{@"2015/10/08":[UIColor brownColor], @"2015/10/17":[UIColor magentaColor], @"2015/10/21":FSCalendarStandardSelectionColor, @"2015/10/25":[UIColor blackColor], - @"2015/11/8":[UIColor brownColor], + @"2015/11/08":[UIColor brownColor], @"2015/11/17":[UIColor magentaColor], @"2015/11/21":FSCalendarStandardSelectionColor, @"2015/11/25":[UIColor blackColor], - @"2015/12/8":[UIColor brownColor], + @"2015/12/08":[UIColor brownColor], @"2015/12/17":[UIColor magentaColor], @"2015/12/21":FSCalendarStandardSelectionColor, @"2015/12/25":[UIColor blackColor]}; - self.borderSelectionColors = @{@"2015/10/8":[UIColor redColor], + self.borderSelectionColors = @{@"2015/10/08":[UIColor redColor], @"2015/10/17":[UIColor purpleColor], @"2015/10/21":FSCalendarStandardSelectionColor, @"2015/10/25":FSCalendarStandardTodayColor, - @"2015/11/8":[UIColor redColor], + @"2015/11/08":[UIColor redColor], @"2015/11/17":[UIColor purpleColor], @"2015/11/21":FSCalendarStandardSelectionColor, @"2015/11/25":FSCalendarStandardTodayColor, - @"2015/12/8":[UIColor redColor], + @"2015/12/08":[UIColor redColor], @"2015/12/17":[UIColor purpleColor], @"2015/12/21":FSCalendarStandardSelectionColor, @"2015/12/25":FSCalendarStandardTodayColor}; @@ -142,15 +155,24 @@ return nil; } -- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance selectionColorForDate:(NSDate *)date +- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance fillSelectionColorForDate:(NSDate *)date { NSString *key = [_calendar stringFromDate:date format:@"yyyy/MM/dd"]; - if ([_selectionColors.allKeys containsObject:key]) { - return _selectionColors[key]; + if ([_fillSelectionColors.allKeys containsObject:key]) { + return _fillSelectionColors[key]; } return appearance.selectionColor; } +- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance fillDefaultColorForDate:(NSDate *)date +{ + NSString *key = [_calendar stringFromDate:date format:@"yyyy/MM/dd"]; + if ([_fillDefaultColors.allKeys containsObject:key]) { + return _fillDefaultColors[key]; + } + return nil; +} + - (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance borderDefaultColorForDate:(NSDate *)date { NSString *key = [_calendar stringFromDate:date format:@"yyyy/MM/dd"]; diff --git a/FSCalendar/FSCalendar.h b/FSCalendar/FSCalendar.h index c09e9c4..75d38fa 100644 --- a/FSCalendar/FSCalendar.h +++ b/FSCalendar/FSCalendar.h @@ -152,12 +152,12 @@ NS_ASSUME_NONNULL_BEGIN /** * Asks the delegate for a fill color in selected state for the specific date. */ -- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance selectionColorForDate:(NSDate *)date; +- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance fillSelectionColorForDate:(NSDate *)date; /** * Asks the delegate for a fill color in unselected state for the specific date. */ -- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance fillColorForDate:(NSDate *)date; +- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance fillDefaultColorForDate:(NSDate *)date; /** * Asks the delegate for day text color in unselected state for the specific date. @@ -205,9 +205,11 @@ NS_ASSUME_NONNULL_BEGIN - (FSCalendarCellShape)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance cellShapeForDate:(NSDate *)date; /** - * This function is deprecated + * These functions are deprecated */ - (FSCalendarCellStyle)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance cellStyleForDate:(NSDate *)date FSCalendarDeprecated(-calendar:appearance:cellShapeForDate:); +- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance fillColorForDate:(NSDate *)date FSCalendarDeprecated(-calendar:appearance:fillDefaultColorForDate:); +- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance selectionColorForDate:(NSDate *)date FSCalendarDeprecated(-calendar:appearance:fillSelectionColorForDate:); @end diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index d70101c..2a83a99 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -31,7 +31,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) { - (NSDate *)minimumDateForCalendar; - (NSDate *)maximumDateForCalendar; -- (UIColor *)preferredSelectionColorForDate:(NSDate *)date; +- (UIColor *)preferredFillSelectionColorForDate:(NSDate *)date; - (UIColor *)preferredTitleDefaultColorForDate:(NSDate *)date; - (UIColor *)preferredTitleSelectionColorForDate:(NSDate *)date; - (UIColor *)preferredSubtitleDefaultColorForDate:(NSDate *)date; @@ -1491,8 +1491,8 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) { - (void)invalidateAppearanceForCell:(FSCalendarCell *)cell { - cell.preferredSelectionColor = [self preferredSelectionColorForDate:cell.date]; - cell.preferredFillColor = [self preferredFillColorForDate:cell.date]; + cell.preferredFillSelectionColor = [self preferredFillSelectionColorForDate:cell.date]; + cell.preferredFillDefaultColor = [self preferredFillDefaultColorForDate:cell.date]; cell.preferredTitleDefaultColor = [self preferredTitleDefaultColorForDate:cell.date]; cell.preferredTitleSelectionColor = [self preferredTitleSelectionColorForDate:cell.date]; if (cell.subtitle) { @@ -1693,21 +1693,35 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) { #pragma GCC diagnostic pop } -- (UIColor *)preferredSelectionColorForDate:(NSDate *)date +- (UIColor *)preferredFillDefaultColorForDate:(NSDate *)date { - if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:selectionColorForDate:)]) { - UIColor *color = [self.delegateAppearance calendar:self appearance:self.appearance selectionColorForDate:date]; + if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:fillDefaultColorForDate:)]) { + UIColor *color = [self.delegateAppearance calendar:self appearance:self.appearance fillDefaultColorForDate:date]; return color; } - return nil; -} - -- (UIColor *)preferredFillColorForDate:(NSDate *)date -{ - if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:fillColorForDate:)]) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + else if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:fillColorForDate:)]) { UIColor *color = [self.delegateAppearance calendar:self appearance:self.appearance fillColorForDate:date]; return color; } +#pragma GCC diagnostic pop + return nil; +} + +- (UIColor *)preferredFillSelectionColorForDate:(NSDate *)date +{ + if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:fillSelectionColorForDate:)]) { + UIColor *color = [self.delegateAppearance calendar:self appearance:self.appearance fillSelectionColorForDate:date]; + return color; + } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + else if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:selectionColorForDate:)]) { + UIColor *color = [self.delegateAppearance calendar:self appearance:self.appearance selectionColorForDate:date]; + return color; + } +#pragma GCC diagnostic pop return nil; } diff --git a/FSCalendar/FSCalendarAppearance.m b/FSCalendar/FSCalendarAppearance.m index b7b46ea..c9e9d06 100644 --- a/FSCalendar/FSCalendarAppearance.m +++ b/FSCalendar/FSCalendarAppearance.m @@ -55,7 +55,7 @@ - (void)invalidateHeaderTextColor; - (void)invalidateBorderColors; -- (void)invalidateBackgroundColors; +- (void)invalidateFillColors; - (void)invalidateEventColors; - (void)invalidateCellShapes; @@ -376,7 +376,7 @@ } else { [_backgroundColors removeObjectForKey:@(FSCalendarCellStateSelected)]; } - [self invalidateBackgroundColors]; + [self invalidateFillColors]; } - (UIColor *)selectionColor @@ -391,7 +391,7 @@ } else { [_backgroundColors removeObjectForKey:@(FSCalendarCellStateToday)]; } - [self invalidateBackgroundColors]; + [self invalidateFillColors]; } - (UIColor *)todayColor @@ -406,7 +406,7 @@ } else { [_backgroundColors removeObjectForKey:@(FSCalendarCellStateToday|FSCalendarCellStateSelected)]; } - [self invalidateBackgroundColors]; + [self invalidateFillColors]; } - (UIColor *)todaySelectionColor @@ -564,7 +564,7 @@ [self invalidateFonts]; [self invalidateTextColors]; [self invalidateBorderColors]; - [self invalidateBackgroundColors]; + [self invalidateFillColors]; /* [_calendar.collectionView.visibleCells enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [_calendar invalidateAppearanceForCell:obj]; @@ -595,7 +595,7 @@ [_calendar.collectionView.visibleCells makeObjectsPerformSelector:_cmd]; } -- (void)invalidateBackgroundColors +- (void)invalidateFillColors { [_calendar.collectionView.visibleCells makeObjectsPerformSelector:_cmd]; } diff --git a/FSCalendar/FSCalendarCell.h b/FSCalendar/FSCalendarCell.h index 9be1cbb..01d303e 100644 --- a/FSCalendar/FSCalendarCell.h +++ b/FSCalendar/FSCalendarCell.h @@ -19,7 +19,7 @@ @property (weak, nonatomic) UILabel *subtitleLabel; @property (weak, nonatomic) UIImageView *imageView; -@property (weak, nonatomic) CAShapeLayer *backgroundLayer; +@property (weak, nonatomic) CAShapeLayer *shapeLayer; @property (weak, nonatomic) FSCalendarEventIndicator *eventIndicator; @property (strong, nonatomic) NSDate *date; @@ -35,8 +35,8 @@ @property (readonly, nonatomic) BOOL weekend; -@property (strong, nonatomic) UIColor *preferredSelectionColor; -@property (strong, nonatomic) UIColor *preferredFillColor; +@property (strong, nonatomic) UIColor *preferredFillDefaultColor; +@property (strong, nonatomic) UIColor *preferredFillSelectionColor; @property (strong, nonatomic) UIColor *preferredTitleDefaultColor; @property (strong, nonatomic) UIColor *preferredTitleSelectionColor; @property (strong, nonatomic) UIColor *preferredSubtitleDefaultColor; @@ -52,7 +52,7 @@ - (void)invalidateSubtitleTextColor; - (void)invalidateBorderColors; -- (void)invalidateBackgroundColors; +- (void)invalidateFillColors; - (void)invalidateEventColors; - (void)invalidateCellShapes; diff --git a/FSCalendar/FSCalendarCell.m b/FSCalendar/FSCalendarCell.m index 516398b..402f640 100644 --- a/FSCalendar/FSCalendarCell.m +++ b/FSCalendar/FSCalendarCell.m @@ -14,7 +14,7 @@ @interface FSCalendarCell () -@property (readonly, nonatomic) UIColor *colorForBackgroundLayer; +@property (readonly, nonatomic) UIColor *colorForCellFill; @property (readonly, nonatomic) UIColor *colorForTitleLabel; @property (readonly, nonatomic) UIColor *colorForSubtitleLabel; @property (readonly, nonatomic) UIColor *colorForCellBorder; @@ -54,7 +54,7 @@ shapeLayer.backgroundColor = [UIColor clearColor].CGColor; shapeLayer.hidden = YES; [self.contentView.layer insertSublayer:shapeLayer below:_titleLabel.layer]; - self.backgroundLayer = shapeLayer; + self.shapeLayer = shapeLayer; eventIndicator = [[FSCalendarEventIndicator alloc] initWithFrame:CGRectZero]; eventIndicator.backgroundColor = [UIColor clearColor]; @@ -80,15 +80,15 @@ CGFloat titleHeight = self.bounds.size.height*5.0/6.0; CGFloat diameter = MIN(self.bounds.size.height*5.0/6.0,self.bounds.size.width); diameter = diameter > FSCalendarStandardCellDiameter ? (diameter - (diameter-FSCalendarStandardCellDiameter)*0.5) : diameter; - _backgroundLayer.frame = CGRectMake((self.bounds.size.width-diameter)/2, + _shapeLayer.frame = CGRectMake((self.bounds.size.width-diameter)/2, (titleHeight-diameter)/2, diameter, diameter); - _backgroundLayer.borderWidth = 1.0; - _backgroundLayer.borderColor = [UIColor clearColor].CGColor; + _shapeLayer.borderWidth = 1.0; + _shapeLayer.borderColor = [UIColor clearColor].CGColor; - CGFloat eventSize = _backgroundLayer.frame.size.height/6.0; - _eventIndicator.frame = CGRectMake(0, CGRectGetMaxY(_backgroundLayer.frame)+eventSize*0.17, bounds.size.width, eventSize*0.83); + CGFloat eventSize = _shapeLayer.frame.size.height/6.0; + _eventIndicator.frame = CGRectMake(0, CGRectGetMaxY(_shapeLayer.frame)+eventSize*0.17, bounds.size.width, eventSize*0.83); _imageView.frame = self.contentView.bounds; } @@ -102,7 +102,7 @@ { [super prepareForReuse]; [CATransaction setDisableActions:YES]; - _backgroundLayer.hidden = YES; + _shapeLayer.hidden = YES; [self.contentView.layer removeAnimationForKey:@"opacity"]; } @@ -110,7 +110,7 @@ - (void)performSelecting { - _backgroundLayer.hidden = NO; + _shapeLayer.hidden = NO; #define kAnimationDuration FSCalendarDefaultBounceAnimationDuration @@ -126,7 +126,7 @@ zoomIn.duration = kAnimationDuration/4; group.duration = kAnimationDuration; group.animations = @[zoomOut, zoomIn]; - [_backgroundLayer addAnimation:group forKey:@"bounce"]; + [_shapeLayer addAnimation:group forKey:@"bounce"]; [self configureCell]; #undef kAnimationDuration @@ -187,30 +187,30 @@ } UIColor *borderColor = self.colorForCellBorder; - UIColor *fillColor = self.colorForBackgroundLayer; + UIColor *fillColor = self.colorForCellFill; - BOOL shouldHiddenBackgroundLayer = !self.selected && !self.dateIsToday && !self.dateIsSelected && !borderColor && !fillColor; + BOOL shouldHideShapeLayer = !self.selected && !self.dateIsToday && !self.dateIsSelected && !borderColor && !fillColor; - if (_backgroundLayer.hidden != shouldHiddenBackgroundLayer) { - _backgroundLayer.hidden = shouldHiddenBackgroundLayer; + if (_shapeLayer.hidden != shouldHideShapeLayer) { + _shapeLayer.hidden = shouldHideShapeLayer; } - if (!shouldHiddenBackgroundLayer) { + if (!shouldHideShapeLayer) { CGPathRef path = self.cellShape == FSCalendarCellShapeCircle ? - [UIBezierPath bezierPathWithOvalInRect:_backgroundLayer.bounds].CGPath : - [UIBezierPath bezierPathWithRect:_backgroundLayer.bounds].CGPath; - if (!CGPathEqualToPath(_backgroundLayer.path,path)) { - _backgroundLayer.path = path; + [UIBezierPath bezierPathWithOvalInRect:_shapeLayer.bounds].CGPath : + [UIBezierPath bezierPathWithRect:_shapeLayer.bounds].CGPath; + if (!CGPathEqualToPath(_shapeLayer.path,path)) { + _shapeLayer.path = path; } - CGColorRef backgroundColor = self.colorForBackgroundLayer.CGColor; - if (!CGColorEqualToColor(_backgroundLayer.fillColor, backgroundColor)) { - _backgroundLayer.fillColor = backgroundColor; + CGColorRef fillColor = self.colorForCellFill.CGColor; + if (!CGColorEqualToColor(_shapeLayer.fillColor, fillColor)) { + _shapeLayer.fillColor = fillColor; } CGColorRef borderColor = self.colorForCellBorder.CGColor; - if (!CGColorEqualToColor(_backgroundLayer.strokeColor, borderColor)) { - _backgroundLayer.strokeColor = borderColor; + if (!CGColorEqualToColor(_shapeLayer.strokeColor, borderColor)) { + _shapeLayer.strokeColor = borderColor; } } @@ -273,12 +273,12 @@ - (void)invalidateBorderColors { - _backgroundLayer.strokeColor = self.colorForCellBorder.CGColor; + _shapeLayer.strokeColor = self.colorForCellBorder.CGColor; } -- (void)invalidateBackgroundColors +- (void)invalidateFillColors { - _backgroundLayer.fillColor = self.colorForBackgroundLayer.CGColor; + _shapeLayer.fillColor = self.colorForCellFill.CGColor; } - (void)invalidateEventColors @@ -289,9 +289,9 @@ - (void)invalidateCellShapes { CGPathRef path = self.cellShape == FSCalendarCellShapeCircle ? - [UIBezierPath bezierPathWithOvalInRect:_backgroundLayer.bounds].CGPath : - [UIBezierPath bezierPathWithRect:_backgroundLayer.bounds].CGPath; - _backgroundLayer.path = path; + [UIBezierPath bezierPathWithOvalInRect:_shapeLayer.bounds].CGPath : + [UIBezierPath bezierPathWithRect:_shapeLayer.bounds].CGPath; + _shapeLayer.path = path; } - (void)invalidateImage @@ -302,14 +302,12 @@ #pragma mark - Properties -- (UIColor *)colorForBackgroundLayer +- (UIColor *)colorForCellFill { if (self.dateIsSelected || self.isSelected) { - return self.preferredSelectionColor ?: [self colorForCurrentStateInDictionary:_appearance.backgroundColors]; - } else if (!self.dateIsToday) { - return self.preferredFillColor; + return self.preferredFillSelectionColor ?: [self colorForCurrentStateInDictionary:_appearance.backgroundColors]; } - return [self colorForCurrentStateInDictionary:_appearance.backgroundColors]; + return self.preferredFillDefaultColor ?: [self colorForCurrentStateInDictionary:_appearance.backgroundColors]; } - (UIColor *)colorForTitleLabel