Skip to content

Commit

Permalink
Add property in rect class for check is isVecation or weekEnd or not
Browse files Browse the repository at this point in the history
Implemenr setter and setter methods of locale and calendarIdentifier
  • Loading branch information
Husseinhj committed Nov 7, 2017
1 parent c03576e commit a6e8062
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions ios_calendar/Sources/CalendarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef NS_ENUM(NSInteger, CalendarEvent)
@property NSInteger value;
@property NSString *str;
@property CGRect frame;
@property BOOL isVecation;

@end

Expand Down
46 changes: 45 additions & 1 deletion ios_calendar/Sources/CalendarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,33 @@ - (void)setMode:(NSInteger)m
}
}

#pragma mark - calendarIdentifier getter/setter methods
- (void) setCalendarIdentifier:(NSCalendarIdentifier)calendarIdentifier{
_calendarId = calendarIdentifier;
if (calendarIdentifier == NSCalendarIdentifierPersian) {
self.preferredWeekStartIndex = 0;
}
}
- (NSCalendarIdentifier) calendarIdentifier{
if (_calendarId) {
return _calendarId;
}
return NSCalendarIdentifierGregorian;
}

#pragma mark - locale getter/setter methods
- (void) setLocale:(NSLocale *)locale{
_calenderLocale = locale;
}
- (NSLocale *) locale{
if (_calenderLocale) {
return _calenderLocale;
}
return [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
}

#pragma mark - reload
}
#pragma mark - Refresh

- (void)refresh
Expand Down Expand Up @@ -570,6 +597,11 @@ - (void)drawRect:(CGRect)rect
withFontSize:self.dayFontSize
withColor:self.fontColor
withAlignment:NSTextAlignmentFromCTTextAlignment(kCTCenterTextAlignment)];

NSDictionary *attributesRed = [self generateAttributes:self.fontName
withFontSize:self.dayFontSize
withColor:[UIColor redColor]
withAlignment:NSTextAlignmentFromCTTextAlignment(kCTCenterTextAlignment)];

NSDictionary *attributesWhite = [self generateAttributes:self.fontName
withFontSize:self.dayFontSize
Expand Down Expand Up @@ -671,6 +703,9 @@ - (void)drawRect:(CGRect)rect
attrs = attributesBlack;
}

if (rect.isVecation && attrs != attributesWhite) {
attrs = attributesRed;
}
[rect.str drawUsingRect:rectText withAttributes:attrs];
}
}
Expand Down Expand Up @@ -717,6 +752,11 @@ - (void)drawWeekDays
withFontSize:self.dayFontSize
withColor:self.fontColor
withAlignment:NSTextAlignmentFromCTTextAlignment(kCTCenterTextAlignment)];

NSDictionary *attrsForVecation = [self generateAttributes:self.fontName
withFontSize:self.dayFontSize
withColor:[UIColor redColor]
withAlignment:NSTextAlignmentFromCTTextAlignment(kCTCenterTextAlignment)];

CGFloat x = 0;
CGFloat y = [self getEffectiveWeekDaysYOffset];
Expand All @@ -727,7 +767,11 @@ - (void)drawWeekDays
NSInteger adjustedIndex = i - self.preferredWeekStartIndex;
x = adjustedIndex * (self.dayCellWidth + kCalendarViewDayCellOffset);
NSString *str = [NSString stringWithFormat:@"%@", weekdayNames[i]];
[str drawUsingRect:CGRectMake(x, y, w, h) withAttributes:attrs];
if (self.calendarIdentifier == NSCalendarIdentifierPersian && i == 0) {
[str drawUsingRect:CGRectMake(x, y, w, h) withAttributes:attrsForVecation];
} else {
[str drawUsingRect:CGRectMake(x, y, w, h) withAttributes:attrs];
}
}

for (NSInteger i = 0; i < self.preferredWeekStartIndex; ++i) {
Expand Down

0 comments on commit a6e8062

Please sign in to comment.