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

Added borderTodayColor for appearance #1413

Open
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions Example-Objc/FSCalendar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@
30A495521DCAD9E6000B2F31 /* FSCalendarWeekdayView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarWeekdayView.h; sourceTree = "<group>"; };
30A495531DCAD9E6000B2F31 /* FSCalendarWeekdayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarWeekdayView.m; sourceTree = "<group>"; };
30B0BABF1B8D8E22004B9476 /* FSCalendar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendar.h; sourceTree = "<group>"; };
30B0BAC01B8D8E22004B9476 /* FSCalendar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = FSCalendar.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
30B0BAC01B8D8E22004B9476 /* FSCalendar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = FSCalendar.m; sourceTree = "<group>"; };
30B0BAC11B8D8E22004B9476 /* FSCalendarAppearance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarAppearance.h; sourceTree = "<group>"; };
30B0BAC21B8D8E22004B9476 /* FSCalendarAppearance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarAppearance.m; sourceTree = "<group>"; };
30B0BAC31B8D8E22004B9476 /* FSCalendarCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = FSCalendarCell.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
30B0BAC31B8D8E22004B9476 /* FSCalendarCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = FSCalendarCell.h; sourceTree = "<group>"; };
30B0BAC41B8D8E22004B9476 /* FSCalendarCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSCalendarCell.m; sourceTree = "<group>"; };
30B0BAC51B8D8E22004B9476 /* FSCalendarDynamicHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarDynamicHeader.h; sourceTree = "<group>"; };
30B0BAC61B8D8E22004B9476 /* FSCalendarHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarHeaderView.h; sourceTree = "<group>"; };
Expand Down
26 changes: 11 additions & 15 deletions FSCalendar/FSCalendar.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Wenchao Ding on 29/1/15.
// Copyright © 2016 Wenchao Ding. All rights reserved.
//
//
// https://github.com/WenchaoD
//
// FSCalendar is a superior awesome calendar control with high performance, high customizablility and very simple usage.
Expand Down Expand Up @@ -151,7 +151,7 @@ NS_ASSUME_NONNULL_BEGIN
@end

/**
* FSCalendarDelegateAppearance determines the fonts and colors of components in the calendar, but more specifically. Basically, if you need to make a global customization of appearance of the calendar, use FSCalendarAppearance. But if you need different appearance for different days, use FSCalendarDelegateAppearance.
* FSCalendarDelegateAppearance determines the fonts and colors of components in the calendar, but more specificly. Basically, if you need to make a global customization of appearance of the calendar, use FSCalendarAppearance. But if you need different appearance for different days, use FSCalendarDelegateAppearance.
*
* @see FSCalendarAppearance
*/
Expand Down Expand Up @@ -242,11 +242,6 @@ NS_ASSUME_NONNULL_BEGIN
IB_DESIGNABLE
@interface FSCalendar : UIView

/**
* The timezone of the calendar. `defaultTimeZone` by default.
*/
@property (strong, nonatomic) NSTimeZone *timeZone;

/**
* The object that acts as the delegate of the calendar.
*/
Expand All @@ -273,13 +268,13 @@ IB_DESIGNABLE
* The locale of month and weekday symbols. Change it to display them in your own language.
*
* e.g. To display them in Chinese:
*
*
* calendar.locale = [NSLocale localeWithLocaleIdentifier:@"zh-CN"];
*/
@property (copy, nonatomic) NSLocale *locale;

/**
* The scroll direction of FSCalendar.
* The scroll direction of FSCalendar.
*
* e.g. To make the calendar scroll vertically
*
Expand All @@ -288,7 +283,7 @@ IB_DESIGNABLE
@property (assign, nonatomic) FSCalendarScrollDirection scrollDirection;

/**
* The scope of calendar, change scope will trigger an inner frame change, make sure the frame has been correctly adjusted in
* The scope of calendar, change scope will trigger an inner frame change, make sure the frame has been correctly adjusted in
*
* - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated;
*/
Expand All @@ -301,8 +296,8 @@ IB_DESIGNABLE

e.g.

UIPanGestureRecognizer *scopeGesture = [[UIPanGestureRecognizer alloc] initWithTarget:calendar action:@selector(handleScopeGesture:)];
[calendar addGestureRecognizer:scopeGesture];
UIPanGestureRecognizer *scopeGesture = [[UIPanGestureRecognizer alloc] initWithTarget:calendar action:@selector(handleScopeGesture:)];
[calendar addGestureRecognizer:scopeGesture];

@see DIYExample
@see FSCalendarScopeExample
Expand Down Expand Up @@ -452,15 +447,15 @@ IB_DESIGNABLE

/**
Register a class for use in creating new calendar cells.

@param cellClass The class of a cell that you want to use in the calendar.
@param identifier The reuse identifier to associate with the specified class. This parameter must not be nil and must not be an empty string.
*/
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier;

/**
Returns a reusable calendar cell object located by its identifier.

@param identifier The reuse identifier for the specified cell. This parameter must not be nil.
@param date The specific date of the cell.
@return A valid FSCalendarCell object.
Expand All @@ -469,7 +464,7 @@ IB_DESIGNABLE

/**
Returns the calendar cell for the specified date.

@param date The date of the cell
@param position The month position for the cell
@return An object representing a cell of the calendar, or nil if the cell is not visible or date is out of range.
Expand Down Expand Up @@ -553,6 +548,7 @@ IB_DESIGNABLE
@property (strong, nonatomic) IBInspectable UIColor *todaySelectionColor;

@property (strong, nonatomic) IBInspectable UIColor *borderDefaultColor;
@property (strong, nonatomic) IBInspectable UIColor *borderTodayColor;
@property (strong, nonatomic) IBInspectable UIColor *borderSelectionColor;

@property (assign, nonatomic) IBInspectable CGFloat borderRadius;
Expand Down
26 changes: 4 additions & 22 deletions FSCalendar/FSCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ @interface FSCalendar ()<UICollectionViewDataSource,UICollectionViewDelegate,FSC

@property (strong, nonatomic) NSCalendar *gregorian;
@property (strong, nonatomic) NSDateFormatter *formatter;
@property (strong, nonatomic) NSTimeZone *timeZone;

@property (weak , nonatomic) UIView *contentView;
@property (weak , nonatomic) UIView *daysContainer;
Expand Down Expand Up @@ -144,7 +145,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder
}

- (void)initialize
{
{
_appearance = [[FSCalendarAppearance alloc] init];
_appearance.calendar = self;

Expand Down Expand Up @@ -279,12 +280,6 @@ - (void)setValue:(id)value forUndefinedKey:(NSString *)key

}

- (void)setTimeZone:(NSTimeZone *)tz
{
_timeZone = tz;
[self invalidateDateTools];
}

- (void)layoutSubviews
{
[super layoutSubviews];
Expand Down Expand Up @@ -706,7 +701,7 @@ - (void)setToday:(NSDate *)today
_today = nil;
} else {
FSCalendarAssertDateInBounds(today,self.gregorian,self.minimumDate,self.maximumDate);
[self updateToday];
_today = [self.gregorian startOfDayForDate:today];
}
if (self.hasValidateVisibleLayout) {
[self.visibleCells makeObjectsPerformSelector:@selector(setDateIsToday:) withObject:nil];
Expand Down Expand Up @@ -1277,19 +1272,6 @@ - (void)invalidateDateTools
_formatter.calendar = _gregorian;
_formatter.timeZone = _timeZone;
_formatter.locale = _locale;

[self updateToday];
}

- (void)updateToday
{
NSDateComponents *dateComponents = [self.gregorian components:(NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay) fromDate:[NSDate date]];
dateComponents.hour = 0;
dateComponents.minute = 0;
dateComponents.second = 0;
dateComponents.timeZone = self.timeZone;

_today = [self.gregorian dateFromComponents:dateComponents];
}

- (void)invalidateLayout
Expand Down Expand Up @@ -1475,7 +1457,7 @@ - (void)selectCounterpartDate:(NSDate *)date
}
if (cell) {
cell.selected = YES;
if (self.collectionView.allowsMultipleSelection) {
if (self.collectionView.allowsMultipleSelection) {
[self.collectionView selectItemAtIndexPath:[self.collectionView indexPathForCell:cell] animated:NO scrollPosition:UICollectionViewScrollPositionNone];
}
}
Expand Down
7 changes: 7 additions & 0 deletions FSCalendar/FSCalendarAppearance.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) {
*/
@property (strong, nonatomic) UIColor *borderDefaultColor;


/**
* The border color of the shape for today state.
*/
@property (strong, nonatomic) UIColor *borderTodayColor;


/**
* The border color of the shape for selected state.
*/
Expand Down
20 changes: 20 additions & 0 deletions FSCalendar/FSCalendarAppearance.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ - (instancetype)init

_borderColors[@(FSCalendarCellStateSelected)] = [UIColor clearColor];
_borderColors[@(FSCalendarCellStateNormal)] = [UIColor clearColor];
_borderColors[@(FSCalendarCellStateToday)] = [UIColor clearColor];
_borderColors[@(FSCalendarCellStateDisabled)] = [UIColor clearColor];

_borderRadius = 1.0;
_eventDefaultColor = FSCalendarStandardEventDotColor;
Expand Down Expand Up @@ -371,6 +373,24 @@ - (UIColor *)borderDefaultColor
return _borderColors[@(FSCalendarCellStateNormal)];
}


- (void)setBorderTodayColor:(UIColor *)color
{
if (color) {
_borderColors[@(FSCalendarCellStateToday)] = color;
} else {
[_borderColors removeObjectForKey:@(FSCalendarCellStateToday)];
}
[self.calendar configureAppearance];
}

- (UIColor *)borderTodayColor
{
return _borderColors[@(FSCalendarCellStateToday)];
}



- (void)setBorderSelectionColor:(UIColor *)color
{
if (color) {
Expand Down
1 change: 1 addition & 0 deletions FSCalendar/FSCalendarCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarMonthPosition);
@property (strong, nonatomic) UIColor *preferredSubtitleDefaultColor;
@property (strong, nonatomic) UIColor *preferredSubtitleSelectionColor;
@property (strong, nonatomic) UIColor *preferredBorderDefaultColor;
@property (strong, nonatomic) UIColor *preferredBorderTodayColor;
@property (strong, nonatomic) UIColor *preferredBorderSelectionColor;
@property (assign, nonatomic) CGPoint preferredTitleOffset;
@property (assign, nonatomic) CGPoint preferredSubtitleOffset;
Expand Down
26 changes: 14 additions & 12 deletions FSCalendar/FSCalendarCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder
}

- (void)commonInit
{
{
UILabel *label;
CAShapeLayer *shapeLayer;
UIImageView *imageView;
Expand Down Expand Up @@ -150,7 +150,7 @@ - (void)layoutSubviews
CGRectGetMaxY(_shapeLayer.frame)+eventSize*0.17+self.preferredEventOffset.y,
self.fs_width,
eventSize*0.83
);
);

}

Expand All @@ -169,7 +169,7 @@ - (void)prepareForReuse
- (void)performSelecting
{
_shapeLayer.opacity = 1;

CAAnimationGroup *group = [CAAnimationGroup animation];
CABasicAnimation *zoomOut = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
zoomOut.fromValue = @0.3;
Expand Down Expand Up @@ -249,7 +249,7 @@ - (void)configureAppearance

_eventIndicator.numberOfEvents = self.numberOfEvents;
_eventIndicator.color = self.colorsForEvents;

}

- (UIColor *)colorForCurrentStateInDictionary:(NSDictionary *)dictionary
Expand Down Expand Up @@ -301,9 +301,11 @@ - (UIColor *)colorForSubtitleLabel
- (UIColor *)colorForCellBorder
{
if (self.selected) {
return _preferredBorderSelectionColor ?: _appearance.borderSelectionColor;
return self.preferredBorderSelectionColor ?: [self colorForCurrentStateInDictionary:_appearance.borderColors];
}
return _preferredBorderDefaultColor ?: _appearance.borderDefaultColor;
return self.preferredBorderDefaultColor ?: [self colorForCurrentStateInDictionary:_appearance.borderColors];


}

- (NSArray<UIColor *> *)colorsForEvents
Expand All @@ -325,16 +327,16 @@ - (CGFloat)borderRadius
\
- (void)set##CAPITAL:(CGPoint)NAME \
{ \
BOOL diff = !CGPointEqualToPoint(NAME, self.NAME); \
_##NAME = NAME; \
if (diff) { \
[self setNeedsLayout]; \
} \
BOOL diff = !CGPointEqualToPoint(NAME, self.NAME); \
_##NAME = NAME; \
if (diff) { \
[self setNeedsLayout]; \
} \
} \
\
- (CGPoint)NAME \
{ \
return CGPointEqualToPoint(_##NAME, CGPointInfinity) ? ALTERNATIVE : _##NAME; \
return CGPointEqualToPoint(_##NAME, CGPointInfinity) ? ALTERNATIVE : _##NAME; \
}

OFFSET_PROPERTY(preferredTitleOffset, PreferredTitleOffset, _appearance.titleOffset);
Expand Down