Today's Menu  Portugal
journal and plan nutrition
Instance Methods | Protected Attributes | Properties | List of all members
CalendarView Class Reference

#import <CalendarView.h>

Inheritance diagram for CalendarView:
Inheritance graph
[legend]
Collaboration diagram for CalendarView:
Collaboration graph
[legend]

Instance Methods

(instancetype) - initWithPosition:y:
 
(void) - setMode:
 
(void) - refresh
 
(void) - goToToday
 
(void) - advanceCalendarContents
 
(void) - rewindCalendarContents
 
(NSDictionary *) - generateAttributes:withFontSize:withColor:withAlignment:
 
(void) - drawCircle:toContext:withColor:
 
(instancetype) - init [implementation]
 
(instancetype) - initWithFrame: [implementation]
 
(void) - awakeFromNib [implementation]
 
(void) - dealloc [implementation]
 
(void) - initProperties [implementation]
 
(void) - setup [implementation]
 
(void) - setCalendarIdentifier: [implementation]
 
(void) - setLocale: [implementation]
 
(void) - setCurrentDate: [implementation]
 
(NSDateComponents *) - generateDateComponents [implementation]
 
(NSDate *) - generateDateWithDay:month:year: [implementation]
 
(NSInteger) - getLastDayOfMonth:year: [implementation]
 
(void) - generateDayRects [implementation]
 
(void) - generatePersianDayRects [implementation]
 
(void) - generateMonthRects [implementation]
 
(void) - generateYearRects [implementation]
 
(CGFloat) - getEffectiveWeekDaysYOffset [implementation]
 
(CGFloat) - getEffectiveDaysYOffset [implementation]
 
(CGFloat) - getEffectiveMonthsYOffset [implementation]
 
(CGFloat) - getEffectiveYearsYOffset [implementation]
 
(void) - drawRect: [implementation]
 
(void) - drawRoundedRectangle:toContext: [implementation]
 
(void) - drawWeekDays [implementation]
 
(void) - changeDateEvent [implementation]
 
(void) - selectRangeOfCalendar [implementation]
 
(void) - advanceCalendarContentsWithEvent: [implementation]
 
(void) - rewindCalendarContentsWithEvent: [implementation]
 
(void) - leftSwipe: [implementation]
 
(void) - rightSwipe: [implementation]
 
(void) - pinch: [implementation]
 
(void) - tap: [implementation]
 
(void) - doubleTap: [implementation]
 
(void) - longPress: [implementation]
 
(BOOL) - checkPoint:inArray:andSetValue: [implementation]
 
(CalendarViewRect *) - checkPoint:inArray: [implementation]
 
(void) - fade [implementation]
 

Protected Attributes

NSInteger type
 
NSInteger minType
 
NSInteger mode
 
NSInteger event
 
NSInteger currentDay
 
NSInteger currentMonth
 
NSInteger currentYear
 
NSInteger todayDay
 
NSInteger todayMonth
 
NSInteger todayYear
 
NSMutableArray * monthRects
 
NSMutableArray * yearRects
 
CGRect yearTitleRect
 
CGRect monthTitleRect
 
NSInteger startRangeDay
 
NSInteger startRangeMonth
 
NSInteger startRangeYear
 
CalendarViewRectstartRangeDayRect
 
NSDate * startDate
 
NSInteger endRangeDay
 
NSInteger endRangeMonth
 
NSInteger endRangeYear
 
CalendarViewRectendRangeDayRect
 
NSDate * endDate
 

Properties

NSMutableArray * dayRects
 
id< CalendarViewDelegate > calendarDelegate
 
NSDate * currentDate
 
UIColor * fontColor
 
UIColor * fontHeaderColor
 
UIColor * fontSelectedColor
 
UIColor * selectionColor
 
UIColor * todayColor
 
UIColor * bgColor
 
CGFloat dayCellWidth
 
CGFloat dayCellHeight
 
CGFloat monthCellWidth
 
CGFloat monthCellHeight
 
CGFloat yearCellWidth
 
CGFloat yearCellHeight
 
NSString * fontName
 
CGFloat dayFontSize
 
CGFloat headerFontSize
 
BOOL shouldMarkSelectedDate
 
BOOL shouldMarkToday
 
BOOL shouldShowHeaders
 
NSCalendarIdentifier calendarIdentifier
 
NSLocale * locale
 
NSInteger preferredWeekStartIndex
 
BOOL useVeryShortWeekdaySymbols
 
NSCalendarIdentifier calendarId [implementation]
 
NSLocale * calenderLocale [implementation]
 

Detailed Description

Definition at line 60 of file CalendarView.h.

Method Documentation

◆ advanceCalendarContents()

- (void) advanceCalendarContents

Definition at line 893 of file CalendarView.m.

894 {
895  [self advanceCalendarContentsWithEvent:CalendarEventNone];
896 }

◆ advanceCalendarContentsWithEvent:()

- (void) advanceCalendarContentsWithEvent: (CalendarEvent)  eventType
implementation

Definition at line 903 of file CalendarView.m.

903  :(CalendarEvent)eventType
904 {
905  event = eventType;
906 
907  switch (type) {
908  case CalendarViewTypeDay:
909  {
910  if (currentMonth == kCalendarViewMonthInYear) {
911  currentMonth = 1;
912  ++currentYear;
913  }
914  else {
915  ++currentMonth;
916  }
917 
918  if (self.calendarIdentifier == NSCalendarIdentifierPersian) {
919  [self generatePersianDayRects];
920  } else {
921  [self generateDayRects];
922  }
923  }
924  break;
925  case CalendarViewTypeMonth:
926  {
927  ++currentYear;
928  }
929  break;
930  case CalendarViewTypeYear:
931  {
933  [self generateYearRects];
934  }
935  break;
936 
937  default:
938  break;
939  }
940 
941  [self changeDateEvent];
942  [self fade];
943 }
NSInteger currentMonth
Definition: CalendarView.m:67
NSInteger currentYear
Definition: CalendarView.m:68
static const NSInteger kCalendarViewMonthInYear
Definition: CalendarView.m:47
static const NSInteger kCalendarViewYearsAround
Definition: CalendarView.m:30
NSCalendarIdentifier calendarIdentifier
Definition: CalendarView.h:100

◆ awakeFromNib()

- (void) awakeFromNib
implementation

Definition at line 164 of file CalendarView.m.

165 {
166  [super awakeFromNib];
167  [self initProperties];
168  [self setup];
169 }

◆ changeDateEvent()

- (void) changeDateEvent
implementation

Definition at line 872 of file CalendarView.m.

873 {
874  NSDate *currentDate = [self currentDate];
875  if (_calendarDelegate && [_calendarDelegate respondsToSelector:@selector(didChangeCalendarDate:)]) {
876  [_calendarDelegate didChangeCalendarDate:currentDate];
877  }
878  if (_calendarDelegate && [_calendarDelegate respondsToSelector:@selector(didChangeCalendarDate:withType:withEvent:)]) {
879  [_calendarDelegate didChangeCalendarDate:currentDate withType:type withEvent:event];
880  }
881 }
NSDate * currentDate
Definition: CalendarView.h:72

◆ checkPoint:inArray:()

- (CalendarViewRect *) checkPoint: (CGPoint)  point
inArray: (NSMutableArray *)  array 
implementation

Definition at line 1184 of file CalendarView.m.

1184  :(CGPoint)point inArray:(NSMutableArray *)array{
1185  for (CalendarViewRect *rect in array) {
1186  if (CGRectContainsPoint(rect.frame, point)) {
1187  return rect;
1188  }
1189  }
1190  return nil;
1191 }

◆ checkPoint:inArray:andSetValue:()

- (BOOL) checkPoint: (CGPoint)  point
inArray: (NSMutableArray *)  array
andSetValue: (NSInteger *)  value 
implementation

Definition at line 1175 of file CalendarView.m.

1175  :(CGPoint)point inArray:(NSMutableArray *)array andSetValue:(NSInteger *)value{
1176  CalendarViewRect *rect = [self checkPoint:point inArray:array];
1177  if (!rect) {
1178  return NO;
1179  }
1180  *value = rect.value;
1181  return YES;
1182 }
NSInteger value
Definition: CalendarView.h:41

◆ dealloc()

- (void) dealloc
implementation

Definition at line 171 of file CalendarView.m.

172 {
173  self.currentDate = nil;
174  self.fontColor = nil;
175  self.fontHeaderColor = nil;
176  self.fontSelectedColor = nil;
177  self.selectionColor = nil;
178  self.fontName = nil;
179 }

◆ doubleTap:()

- (void) doubleTap: (UITapGestureRecognizer *)  recognizer
implementation

Definition at line 1072 of file CalendarView.m.

1072  :(UITapGestureRecognizer *)recognizer
1073 {
1074  event = CalendarEventDoubleTap;
1075  if (type != CalendarViewTypeDay && type > minType) {
1076  --type;
1077  [self fade];
1078  }
1079 
1080  if (type == CalendarViewTypeDay) {
1081  if (self.calendarIdentifier == NSCalendarIdentifierPersian) {
1082  [self generatePersianDayRects];
1083  } else {
1084  [self generateDayRects];
1085  }
1086  }
1087 
1088  NSDate *currentDate = [self currentDate];
1089  if (event == CalendarEventDoubleTap && _calendarDelegate && [_calendarDelegate respondsToSelector:@selector(didDoubleTapCalendar:withType:)]) {
1090  [_calendarDelegate didDoubleTapCalendar:currentDate withType:type];
1091  }
1092 }
NSDate * currentDate
Definition: CalendarView.h:72
NSInteger type
Definition: CalendarView.m:61
NSCalendarIdentifier calendarIdentifier
Definition: CalendarView.h:100

◆ drawCircle:toContext:withColor:()

- (void) drawCircle: (CGRect)  rect
toContext: (CGContextRef *)  context
withColor: (UIColor *)  color 

Definition at line 795 of file CalendarView.m.

795  :(CGRect)rect toContext:(CGContextRef *)context withColor:(UIColor *)color
796 {
797  CGContextSetFillColorWithColor(*context, color.CGColor);
798  CGContextFillEllipseInRect(*context, rect);
799 }

◆ drawRect:()

- (void) drawRect: (CGRect)  rect
implementation

Reimplemented in B2NutritionCalendarView.

Definition at line 645 of file CalendarView.m.

645  :(CGRect)rect
646 {
647  CGContextRef context = UIGraphicsGetCurrentContext();
648  CGContextClearRect(context, rect);
649 
650  CGContextSetFillColorWithColor(context, self.bgColor.CGColor);
651  CGContextFillRect(context, rect);
652 
653  NSDictionary *attributesBlack = [self generateAttributes:self.fontName
654  withFontSize:self.dayFontSize
655  withColor:self.fontColor
656  withAlignment:NSTextAlignmentFromCTTextAlignment(kCTTextAlignmentCenter)];
657 
658  NSDictionary *attributesRed = [self generateAttributes:self.fontName
659  withFontSize:self.dayFontSize
660  withColor:[UIColor redColor]
661  withAlignment:NSTextAlignmentFromCTTextAlignment(kCTTextAlignmentCenter)];
662 
663  NSDictionary *attributesWhite = [self generateAttributes:self.fontName
664  withFontSize:self.dayFontSize
665  withColor:self.fontSelectedColor
666  withAlignment:NSTextAlignmentFromCTTextAlignment(kCTTextAlignmentCenter)];
667 
668  NSDictionary *attributesRedRight = [self generateAttributes:self.fontName
669  withFontSize:self.headerFontSize
670  withColor:self.fontHeaderColor
671  withAlignment:NSTextAlignmentFromCTTextAlignment(kCTTextAlignmentRight)];
672 
673  NSDictionary *attributesRedLeft = [self generateAttributes:self.fontName
674  withFontSize:self.headerFontSize
675  withColor:self.fontHeaderColor
676  withAlignment:NSTextAlignmentFromCTTextAlignment(kCTTextAlignmentLeft)];
677 
678  CTFontRef cellFont = CTFontCreateWithName((__bridge CFStringRef)self.fontName, self.dayFontSize, NULL);
679  CGRect cellFontBoundingBox = CTFontGetBoundingBox(cellFont);
680  CFRelease(cellFont);
681 
682  NSNumberFormatter *yearFormater = [[NSNumberFormatter alloc] init];
683  yearFormater.locale = self.locale;
684  NSString *year = [yearFormater stringForObjectValue:@(currentYear)];
685  const CGFloat yearNameX = (self.dayCellWidth - CGRectGetHeight(cellFontBoundingBox)) * 0.5;
686  if (self.shouldShowHeaders) {
688  } else {
689  yearTitleRect = CGRectZero;
690  }
691  [year drawUsingRect:yearTitleRect withAttributes:attributesRedLeft];
692 
693  if (mode != CalendarModeYears) {
694  NSDateFormatter *formater = [NSDateFormatter new];
695  formater.locale = self.locale;
696  NSArray *monthNames = [formater standaloneMonthSymbols];
697  NSString *monthName = monthNames[(currentMonth - 1)];
698  const CGFloat monthNameX = (self.dayCellWidth + kCalendarViewDayCellOffset) * kCalendarViewDaysInWeek - kCalendarViewMonthLabelWidth - (self.dayCellWidth - CGRectGetHeight(cellFontBoundingBox));
699  if (self.shouldShowHeaders) {
701  } else {
702  monthTitleRect = CGRectZero;
703  }
704  [monthName drawUsingRect:monthTitleRect withAttributes:attributesRedRight];
705  }
706 
707  NSMutableArray *rects = nil;
708  NSInteger currentValue = 0;
709 
710  switch (type) {
711  case CalendarViewTypeDay:
712  {
713  [self drawWeekDays];
714 
715  rects = _dayRects;
716  currentValue = currentDay;
717  }
718  break;
719  case CalendarViewTypeMonth:
720  {
721  rects = monthRects;
722  currentValue = currentMonth;
723  }
724  break;
725  case CalendarViewTypeYear:
726  {
727  rects = yearRects;
728  currentValue = currentYear;
729  }
730  break;
731 
732  default:
733  break;
734  }
735 
736  if (rects) {
737  for (CalendarViewRect *rect in rects) {
738  NSDictionary *attrs = attributesBlack;
739  CGRect rectText = rect.frame;
740  rectText.origin.y = rectText.origin.y + ((CGRectGetHeight(rectText) - CGRectGetHeight(cellFontBoundingBox)) * 0.5);
741 
742  if (type == CalendarViewTypeDay && (((rect.value >= startRangeDay && rect.value <= endRangeDay) && currentMonth >= startRangeMonth && currentYear >= startRangeYear) || ((rect.value >= startRangeDay && rect.value <= endRangeDay) && currentMonth <= endRangeMonth && currentYear <= endRangeYear))) {
743  if (type == CalendarViewTypeDay) {
744  [self drawCircle:rect.frame toContext:&context withColor:self.selectionColor];
745  }
746 
747  attrs = attributesWhite;
748  } else if ((type == CalendarViewTypeYear && (rect.value >= startRangeYear && rect.value <= endRangeYear)) || (endRangeYear == 0 && (type == CalendarViewTypeYear && rect.value == startRangeYear))) {
749  [self drawRoundedRectangle:rect.frame toContext:&context];
750  attrs = attributesWhite;
751  } else if ((type == CalendarViewTypeMonth && (rect.value >= startRangeMonth && rect.value <= endRangeMonth)) || (endRangeMonth == 0 && (type == CalendarViewTypeMonth && rect.value == startRangeMonth))) {
752  [self drawRoundedRectangle:rect.frame toContext:&context];
753  attrs = attributesWhite;
754  } else if ((startRangeDay == 0 && rect.value == currentValue && self.shouldMarkSelectedDate) ||
755  (rect.value == startRangeDay && currentMonth == startRangeMonth && currentYear == startRangeYear && type == CalendarViewTypeDay)) {
756  if (type == CalendarViewTypeDay) {
757  [self drawCircle:rect.frame toContext:&context withColor:self.selectionColor];
758  }
759  else {
760  [self drawRoundedRectangle:rect.frame toContext:&context];
761  }
762 
763  attrs = attributesWhite;
764  } else if (type == CalendarViewTypeDay &&
765  rect.value == todayDay &&
766  currentMonth == todayMonth &&
767  currentYear == todayYear &&
768  self.shouldMarkToday) {
769  [self drawCircle:rect.frame toContext:&context withColor:self.todayColor];
770  attrs = attributesWhite;
771  } else if (type == CalendarViewTypeMonth) {
772  attrs = attributesBlack;
773  } else {
774  attrs = attributesBlack;
775  }
776 
777  if (rect.isVecation && attrs != attributesWhite) {
778  attrs = attributesRed;
779  }
780  [rect.str drawUsingRect:rectText withAttributes:attrs];
781  }
782  }
783  if ((startRangeDay > 0 && startRangeMonth > 0 && startRangeYear > 0) &&
784  (endRangeDay > 0 && endRangeMonth > 0 && endRangeYear > 0)) {
785  startRangeDay = 0;
786  startRangeMonth = 0;
787  startRangeYear = 0;
788 
789  endRangeDay = 0;
790  endRangeMonth = 0;
791  endRangeYear = 0;
792  }
793 }
CGRect yearTitleRect
Definition: CalendarView.m:78
BOOL shouldShowHeaders
Definition: CalendarView.h:98
static const CGFloat kCalendarViewYearLabelWidth
Definition: CalendarView.m:36
UIColor * bgColor
Definition: CalendarView.h:80
NSString * fontName
Definition: CalendarView.h:91
NSInteger startRangeYear
Definition: CalendarView.m:84
NSInteger currentMonth
Definition: CalendarView.m:67
CGRect monthTitleRect
Definition: CalendarView.m:79
NSMutableArray * yearRects
Definition: CalendarView.m:76
NSInteger startRangeMonth
Definition: CalendarView.m:83
static const CGFloat kCalendarViewMonthLabelWidth
Definition: CalendarView.m:33
NSInteger endRangeMonth
Definition: CalendarView.m:89
CGFloat dayCellWidth
Definition: CalendarView.h:83
static const CGFloat kCalendarViewDayCellOffset
Definition: CalendarView.m:18
NSInteger currentYear
Definition: CalendarView.m:68
NSInteger startRangeDay
Definition: CalendarView.m:82
static const NSInteger kCalendarViewDaysInWeek
Definition: CalendarView.m:46
NSMutableArray * monthRects
Definition: CalendarView.m:75
CGFloat dayFontSize
Definition: CalendarView.h:92
NSInteger endRangeDay
Definition: CalendarView.m:88
static const CGFloat kCalendarViewYearLabelHeight
Definition: CalendarView.m:37
NSInteger endRangeYear
Definition: CalendarView.m:90
static const CGFloat kCalendarViewMonthLabelHeight
Definition: CalendarView.m:34
NSInteger currentDay
Definition: CalendarView.m:66

◆ drawRoundedRectangle:toContext:()

- (void) drawRoundedRectangle: (CGRect)  rect
toContext: (CGContextRef *)  context 
implementation

Definition at line 801 of file CalendarView.m.

801  :(CGRect)rect toContext:(CGContextRef *)context
802 {
803  CGContextSetFillColorWithColor(*context, self.selectionColor.CGColor);
804 
805  CGFloat minx = CGRectGetMinX(rect), midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect);
806  CGFloat miny = CGRectGetMinY(rect), midy = CGRectGetMidY(rect), maxy = CGRectGetMaxY(rect);
807 
808  CGContextMoveToPoint(*context, minx, midy);
809  CGContextAddArcToPoint(*context, minx, miny, midx, miny, kCalendarViewSelectionRound);
810  CGContextAddArcToPoint(*context, maxx, miny, maxx, midy, kCalendarViewSelectionRound);
811  CGContextAddArcToPoint(*context, maxx, maxy, midx, maxy, kCalendarViewSelectionRound);
812  CGContextAddArcToPoint(*context, minx, maxy, minx, midy, kCalendarViewSelectionRound);
813  CGContextClosePath(*context);
814 
815  CGContextSetStrokeColorWithColor(*context, self.selectionColor.CGColor);
816  CGContextDrawPath(*context, kCGPathFillStroke);
817 }
UIColor * selectionColor
Definition: CalendarView.h:78
static const CGFloat kCalendarViewSelectionRound
Definition: CalendarView.m:50

◆ drawWeekDays()

- (void) drawWeekDays
implementation

Definition at line 819 of file CalendarView.m.

820 {
821  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
822  dateFormatter.locale = self.locale;
823  NSArray *weekdayNames = [dateFormatter shortWeekdaySymbols];
824  if (_useVeryShortWeekdaySymbols) {
825  weekdayNames = [dateFormatter veryShortWeekdaySymbols];
826  }
827 
828  if (self.calendarIdentifier == NSCalendarIdentifierPersian){
829  NSMutableArray *arrayWeeks = [weekdayNames mutableCopy];
830  [arrayWeeks insertObject:arrayWeeks.lastObject atIndex:0];
831  [arrayWeeks removeObjectAtIndex:arrayWeeks.count-1];
832  weekdayNames = [[arrayWeeks reverseObjectEnumerator] allObjects];
833  }
834 
835  NSDictionary *attrs = [self generateAttributes:self.fontName
836  withFontSize:self.dayFontSize
837  withColor:self.fontColor
838  withAlignment:NSTextAlignmentFromCTTextAlignment(kCTTextAlignmentCenter)];
839 
840  NSDictionary *attrsForVecation = [self generateAttributes:self.fontName
841  withFontSize:self.dayFontSize
842  withColor:[UIColor redColor]
843  withAlignment:NSTextAlignmentFromCTTextAlignment(kCTTextAlignmentCenter)];
844 
845  CGFloat x = 0;
846  CGFloat y = [self getEffectiveWeekDaysYOffset];
847  const CGFloat w = self.dayCellWidth;
848  const CGFloat h = self.dayCellHeight;
849 
850  for (NSInteger i = self.preferredWeekStartIndex; i < kCalendarViewDaysInWeek; ++i) {
851  NSInteger adjustedIndex = i - self.preferredWeekStartIndex;
852  x = adjustedIndex * (self.dayCellWidth + kCalendarViewDayCellOffset);
853  NSString *str = [NSString stringWithFormat:@"%@", weekdayNames[i]];
854  if (self.calendarIdentifier == NSCalendarIdentifierPersian && i == 0) {
855  [str drawUsingRect:CGRectMake(x, y, w, h) withAttributes:attrsForVecation];
856  } else {
857  [str drawUsingRect:CGRectMake(x, y, w, h) withAttributes:attrs];
858  }
859  }
860 
861  for (NSInteger i = 0; i < self.preferredWeekStartIndex; ++i) {
862  NSInteger adjustedIndex = kCalendarViewDaysInWeek - (self.preferredWeekStartIndex - i);
863  x = adjustedIndex * (self.dayCellWidth + kCalendarViewDayCellOffset);
864  NSString *str = [NSString stringWithFormat:@"%@", weekdayNames[i]];
865  [str drawUsingRect:CGRectMake(x, y, w, h) withAttributes:attrs];
866  }
867 
868 }
NSInteger preferredWeekStartIndex
Definition: CalendarView.h:104
static const CGFloat kCalendarViewDayCellOffset
Definition: CalendarView.m:18
static const NSInteger kCalendarViewDaysInWeek
Definition: CalendarView.m:46
NSCalendarIdentifier calendarIdentifier
Definition: CalendarView.h:100

◆ fade()

- (void) fade
implementation

Definition at line 1214 of file CalendarView.m.

1215 {
1216  [UIView animateWithDuration:kCalendarViewSwipeMonthFadeInTime
1217  delay:0
1218  options:0
1219  animations:^{
1220  self.alpha = 0.0f;
1221  }
1222  completion:^(BOOL finished) {
1223  [self setNeedsDisplay];
1224  [UIView animateWithDuration:kCalendarViewSwipeMonthFadeOutTime
1225  delay:0
1226  options:0
1227  animations:^{
1228  self.alpha = 1.0f;
1229  }
1230  completion:nil];
1231  }];
1232 }

◆ generateAttributes:withFontSize:withColor:withAlignment:()

- (NSDictionary *) generateAttributes: (NSString *)  fontName
withFontSize: (CGFloat)  fontSize
withColor: (UIColor *)  color
withAlignment: (NSTextAlignment)  textAlignment 

Definition at line 1193 of file CalendarView.m.

1193  :(NSString *)fontName withFontSize:(CGFloat)fontSize withColor:(UIColor *)color withAlignment:(NSTextAlignment)textAlignment
1194 {
1195  NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
1196  [paragraphStyle setAlignment:textAlignment];
1197  [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
1198 
1199  UIFont *font = nil;
1200  if ([self.fontName isEqualToString:@"TrebuchetMS"] && self.calendarIdentifier == NSCalendarIdentifierPersian) {
1201  font = [UIFont systemFontOfSize:fontSize];
1202  } else {
1203  font = [UIFont fontWithName:self.fontName size:fontSize];
1204  }
1205  NSDictionary * attrs = @{
1206  NSFontAttributeName : font,
1207  NSForegroundColorAttributeName : color,
1208  NSParagraphStyleAttributeName : paragraphStyle
1209  };
1210 
1211  return attrs;
1212 }
NSString * fontName
Definition: CalendarView.h:91
NSCalendarIdentifier calendarIdentifier
Definition: CalendarView.h:100

◆ generateDateComponents()

- (NSDateComponents *) generateDateComponents
implementation

Definition at line 384 of file CalendarView.m.

384  {
385  NSDate *now = [NSDate date];
386  NSTimeZone *timeZone = [NSTimeZone timeZoneWithAbbreviation:@"America/Los Angeles"];
387  NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:self.calendarIdentifier];
388  [calendar setTimeZone:timeZone];
389 
390  NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:now];
391 
392  [components setCalendar:calendar];
393  [components setTimeZone:timeZone];
394 
395  return components;
396 }

◆ generateDateWithDay:month:year:()

- (NSDate *) generateDateWithDay: (NSInteger)  day
month: (NSInteger)  month
year: (NSInteger)  year 
implementation

Definition at line 398 of file CalendarView.m.

398  :(NSInteger) day month:(NSInteger) month year:(NSInteger) year{
399  NSDateComponents *components = [self generateDateComponents];
400 
401  [components setYear:year];
402  [components setMonth:month];
403  [components setDay:day];
404  [components setHour:0];
405  [components setMinute:0];
406  [components setSecond:0];
407 
408  return [components.calendar dateFromComponents:components];
409 }

◆ generateDayRects()

- (void) generateDayRects
implementation

Definition at line 420 of file CalendarView.m.

421 {
422  [_dayRects removeAllObjects];
423 
424  NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:self.calendarIdentifier];
425  NSUInteger lastDayOfMonth = [self getLastDayOfMonth:currentMonth year:currentYear];
426 
427  if (currentDay > lastDayOfMonth) {
428  currentDay = lastDayOfMonth;
429  }
430 
431  NSDate *currentDate = [self generateDateWithDay:currentDay month:currentMonth year:currentYear];
432  NSInteger weekday = [currentDate getWeekdayOfFirstDayOfMonthForCalendar:calendar];
433 
434  const CGFloat yOffSet = [self getEffectiveDaysYOffset];
435  const CGFloat w = self.dayCellWidth;
436  const CGFloat h = self.dayCellHeight;
437 
438  CGFloat x = 0;
439  CGFloat y = yOffSet;
440 
441  NSInteger xi = weekday - self.preferredWeekStartIndex;
442  NSInteger yi = 0;
443 
444  NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
445  formatter.locale = self.locale;
446 
447  for (NSInteger i = 1; i <= lastDayOfMonth; ++i) {
448  x = xi * (self.dayCellWidth + kCalendarViewDayCellOffset);
449  ++xi;
450 
451  CalendarViewRect *dayRect = [[CalendarViewRect alloc] init];
452  dayRect.value = i;
453  dayRect.str = [formatter stringForObjectValue:@(i)];
454  dayRect.frame = CGRectMake(x, y, w, h);
455  [_dayRects addObject:dayRect];
456 
457  if (xi >= kCalendarViewDaysInWeek) {
458  xi = 0;
459  ++yi;
460  y = yOffSet + yi * (self.dayCellHeight + kCalendarViewDayCellOffset);
461  }
462  }
463 }
NSDate * currentDate
Definition: CalendarView.h:72
NSString * str
Definition: CalendarView.h:42
CGFloat dayCellHeight
Definition: CalendarView.h:84
NSInteger preferredWeekStartIndex
Definition: CalendarView.h:104
static const CGFloat kCalendarViewDayCellOffset
Definition: CalendarView.m:18
NSInteger value
Definition: CalendarView.h:41
static const NSInteger kCalendarViewDaysInWeek
Definition: CalendarView.m:46
NSInteger currentDay
Definition: CalendarView.m:66

◆ generateMonthRects()

- (void) generateMonthRects
implementation

Definition at line 548 of file CalendarView.m.

549 {
550  [monthRects removeAllObjects];
551 
552  NSDateFormatter *formater = [NSDateFormatter new];
553  formater.locale = self.locale;
554  NSArray *monthNames = [formater standaloneMonthSymbols];
555  NSInteger index = 0;
556  CGFloat x, y = [self getEffectiveMonthsYOffset];
557  NSInteger xi = 0;
558  for (NSString *monthName in monthNames) {
559  x = xi * self.monthCellWidth;
560  ++xi;
561  ++index;
562 
563  CalendarViewRect *monthRect = [[CalendarViewRect alloc] init];
564  monthRect.value = index;
565  monthRect.str = monthName;
566  monthRect.frame = CGRectMake(x, y, self.monthCellWidth, self.monthCellHeight);
567  [monthRects addObject:monthRect];
568 
569  if (xi >= kCalendarViewMonthInLine) {
570  xi = 0;
572  }
573  }
574 }
CGFloat monthCellHeight
Definition: CalendarView.h:86
NSString * str
Definition: CalendarView.h:42
CGFloat monthCellWidth
Definition: CalendarView.h:85
NSInteger value
Definition: CalendarView.h:41
static const CGFloat kCalendarViewMonthYStep
Definition: CalendarView.m:23
static const NSInteger kCalendarViewMonthInLine
Definition: CalendarView.m:24

◆ generatePersianDayRects()

- (void) generatePersianDayRects
implementation

Definition at line 465 of file CalendarView.m.

465  {
466  [_dayRects removeAllObjects];
467 
468  NSDate *now = [NSDate date];
469  NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:self.calendarIdentifier];
470  NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:now];
471  [components setYear:currentYear];
472  [components setMonth:currentMonth];
473  [components setDay:1]; // set first day of month
474 
475  NSDate *currentDate = [calendar dateFromComponents:components];
476  NSUInteger lastDayOfMonth = [currentDate getLastDayOfMonthForCalendar:calendar];
477 
478  NSInteger startDayOfMonth = [currentDate getWeekdayOfFirstDayOfMonthForCalendar:calendar];
479  NSInteger plusRow = startDayOfMonth == 7?2:1;
480  if (startDayOfMonth >= 6 && lastDayOfMonth == 31) {
481  plusRow = 2;
482  }
483  NSInteger weeks = (lastDayOfMonth / 7)+plusRow;
484  NSInteger minimumDayOfWeek = 1;
485  if (startDayOfMonth > 0) {
486  startDayOfMonth = kCalendarViewDaysInWeek - (startDayOfMonth-1);
487  } else {
488  startDayOfMonth = kCalendarViewDaysInWeek;
489  }
490  NSMutableArray *daysOfMonth = [[NSMutableArray alloc] init];
491  for (int i = 1; i <= weeks; i++) {
492  NSMutableArray *arrayOfEachWeek = [[NSMutableArray alloc] init];
493  for (NSInteger j = startDayOfMonth; j >= minimumDayOfWeek ; j--) {
494  if (j > lastDayOfMonth) {
495  break;
496  }
497  [arrayOfEachWeek addObject:@(j)];
498  }
499  [daysOfMonth addObject:arrayOfEachWeek];
500  startDayOfMonth = (startDayOfMonth + kCalendarViewDaysInWeek);
501  minimumDayOfWeek = (startDayOfMonth - kCalendarViewDaysInWeek)+1;
502  if (startDayOfMonth > lastDayOfMonth) {
503  startDayOfMonth = startDayOfMonth - (startDayOfMonth - lastDayOfMonth);
504  }
505  }
506 
507  [components setDay:currentDay];
508  currentDate = [calendar dateFromComponents:components];
509  NSInteger weekday = [currentDate getWeekdayOfFirstDayOfMonthForCalendar:calendar];
510  weekday = weekday == 0 ? 1:weekday;
511  const CGFloat yOffSet = [self getEffectiveDaysYOffset];
512  const CGFloat w = self.dayCellWidth;
513  const CGFloat h = self.dayCellHeight;
514 
515  CGFloat x = 0;
516  CGFloat y = yOffSet;
517 
518  NSInteger xi = kCalendarViewDaysInWeek - weekday;
519  NSInteger yi = 0;
520 
521  NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
522  formatter.locale = self.locale;
523  NSInteger day = 1;
524  for (int i = 0; i < daysOfMonth.count; i++) {
525  NSArray *week = (NSArray *)daysOfMonth[i];
526  for (int j = 0; j < week.count; j++) {
527  x = xi * (self.dayCellWidth + kCalendarViewDayCellOffset);
528  --xi;
529 
530  CalendarViewRect *dayRect = [[CalendarViewRect alloc] init];
531  dayRect.value = day;
532  dayRect.str = [formatter stringForObjectValue:@(day)];
533  dayRect.frame = CGRectMake(x, y, w, h);
534  if (j == kCalendarViewDaysInWeek -1 ||
535  (i < daysOfMonth.count -1 && j == week.count -1)) {
536  dayRect.isVecation = YES;
537  }
538  [_dayRects addObject:dayRect];
539 
540  day ++;
541  }
543  ++yi;
544  y = yOffSet + yi * (self.dayCellHeight + kCalendarViewDayCellOffset);
545  }
546 }
NSDate * currentDate
Definition: CalendarView.h:72
NSString * str
Definition: CalendarView.h:42
CGFloat dayCellHeight
Definition: CalendarView.h:84
static const CGFloat kCalendarViewDayCellOffset
Definition: CalendarView.m:18
NSInteger value
Definition: CalendarView.h:41
static const NSInteger kCalendarViewDaysInWeek
Definition: CalendarView.m:46

◆ generateYearRects()

- (void) generateYearRects
implementation

Definition at line 576 of file CalendarView.m.

577 {
578  [yearRects removeAllObjects];
579 
580  NSMutableArray *years = [[NSMutableArray alloc] init];
581  for (NSInteger year = currentYear - kCalendarViewYearsAround; year <= currentYear + kCalendarViewYearsAround; ++year) {
582  [years addObject:@(year)];
583  }
584 
585  CGFloat x, y = [self getEffectiveYearsYOffset];
586  NSInteger xi = 0;
587  NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
588  formatter.locale = self.locale;
589 
590  for (NSNumber *obj in years) {
591  x = xi * self.yearCellWidth;
592  ++xi;
593 
594  CalendarViewRect *yearRect = [[CalendarViewRect alloc] init];
595  yearRect.value = [obj integerValue];
596  yearRect.str = [formatter stringForObjectValue:@([obj integerValue])];
597  yearRect.frame = CGRectMake(x, y, self.yearCellWidth, self.yearCellHeight);
598  [yearRects addObject:yearRect];
599 
600  if (xi >= kCalendarViewYearsInLine) {
601  xi = 0;
603  }
604  }
605 }
NSString * str
Definition: CalendarView.h:42
NSInteger value
Definition: CalendarView.h:41
NSInteger currentYear
Definition: CalendarView.m:68
static const CGFloat kCalendarViewYearYStep
Definition: CalendarView.m:29
CGFloat yearCellHeight
Definition: CalendarView.h:88
CGFloat yearCellWidth
Definition: CalendarView.h:87
static const NSInteger kCalendarViewYearsInLine
Definition: CalendarView.m:31
static const NSInteger kCalendarViewYearsAround
Definition: CalendarView.m:30

◆ getEffectiveDaysYOffset()

- (CGFloat) getEffectiveDaysYOffset
implementation

Definition at line 618 of file CalendarView.m.

619 {
620  if (self.shouldShowHeaders) {
622  } else {
624  }
625 }
BOOL shouldShowHeaders
Definition: CalendarView.h:98
static const CGFloat kCalendarViewWeekDaysYOffset
Definition: CalendarView.m:39
static const CGFloat kCalendarViewDaysYOffset
Definition: CalendarView.m:40

◆ getEffectiveMonthsYOffset()

- (CGFloat) getEffectiveMonthsYOffset
implementation

Definition at line 627 of file CalendarView.m.

628 {
629  if (self.shouldShowHeaders) {
631  } else {
632  return 0;
633  }
634 }
BOOL shouldShowHeaders
Definition: CalendarView.h:98
static const CGFloat kCalendarViewMonthTitleOffsetY
Definition: CalendarView.m:22

◆ getEffectiveWeekDaysYOffset()

- (CGFloat) getEffectiveWeekDaysYOffset
implementation

Definition at line 609 of file CalendarView.m.

610 {
611  if (self.shouldShowHeaders) {
613  } else {
614  return 0;
615  }
616 }
BOOL shouldShowHeaders
Definition: CalendarView.h:98
static const CGFloat kCalendarViewWeekDaysYOffset
Definition: CalendarView.m:39

◆ getEffectiveYearsYOffset()

- (CGFloat) getEffectiveYearsYOffset
implementation

Definition at line 636 of file CalendarView.m.

637 {
638  if (self.shouldShowHeaders) {
640  } else return 0;
641 }
BOOL shouldShowHeaders
Definition: CalendarView.h:98
static const CGFloat kCalendarViewYearTitleOffsetY
Definition: CalendarView.m:28

◆ getLastDayOfMonth:year:()

- (NSInteger) getLastDayOfMonth: (NSInteger)  month
year: (NSInteger)  year 
implementation

Definition at line 411 of file CalendarView.m.

411  :(NSInteger) month year:(NSInteger) year{
412  NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:self.calendarIdentifier];
413 
414  NSDate *currentDate = [self generateDateWithDay:1 month:month year:year];
415  return [currentDate getLastDayOfMonthForCalendar:calendar];
416 }
NSDate * currentDate
Definition: CalendarView.h:72

◆ goToToday()

- (void) goToToday

Definition at line 322 of file CalendarView.m.

322  {
323  [self setup];
324 }

◆ init()

- (instancetype) init
implementation

Reimplemented in B2NutritionCalendarView.

Definition at line 138 of file CalendarView.m.

139 {
140  self = [self initWithPosition:0.0 y:0.0];
141  return self;
142 }

◆ initProperties()

- (void) initProperties
implementation

Definition at line 183 of file CalendarView.m.

183  {
184  self.dayCellWidth = kCalendarViewDayCellWidth;
185  self.dayCellHeight = kCalendarViewDayCellHeight;
186  self.monthCellWidth = kCalendarViewMonthCellWidth;
187  self.monthCellHeight = kCalendarViewMonthCellHeight;
188  self.yearCellWidth = kCalendarViewYearCellWidth;
189  self.yearCellHeight = kCalendarViewYearCellHeight;
190 
191  self.preferredWeekStartIndex = 1; // This is Monday, from [dateFormatter shortWeekdaySymbols]
192  if (!_fontName) {
193  self.fontName = kCalendarViewDefaultFont;
194  }
195  if (!_dayFontSize) {
196  self.dayFontSize = kCalendarViewDayFontSize;
197  }
198  if (!_headerFontSize) {
199  self.headerFontSize = kCalendarViewHeaderFontSize;
200  }
201 
202  // TODO: check calendar produced by each option
203  [self setMode:CalendarModeDefault];
204  // [self setMode:CalendarModeMonthsAndYears];
205  // [self setMode:CalendarModeYears];
206  self.fontColor = [UIColor blackColor];
207  self.fontHeaderColor = [UIColor redColor];
208  self.fontSelectedColor = [UIColor whiteColor];
209  self.selectionColor = [UIColor redColor];
210  self.todayColor = [UIColor redColor];
211  self.bgColor = [UIColor whiteColor];
212  self.backgroundColor = [UIColor clearColor];
213 
214  self.shouldMarkSelectedDate = YES;
215  self.shouldMarkToday = NO;
216  self.shouldShowHeaders = NO;
217 
218  UISwipeGestureRecognizer *left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe:)];
219  [left setDirection:UISwipeGestureRecognizerDirectionLeft];
220  [self addGestureRecognizer:left];
221 
222  UISwipeGestureRecognizer *right = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipe:)];
223  [right setDirection:UISwipeGestureRecognizerDirectionRight];
224  [self addGestureRecognizer:right];
225 
226  UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];
227  [self addGestureRecognizer:pinch];
228 
229  UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
230  tap.numberOfTapsRequired = 1;
231  [self addGestureRecognizer:tap];
232 
233  UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
234  doubleTap.numberOfTapsRequired = 2;
235  [self addGestureRecognizer:doubleTap];
236 
237  UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self
238  action:@selector(longPress:)];
239 // longPress.numberOfTapsRequired = 1;
240  longPress.numberOfTouchesRequired = 1;
241  longPress.minimumPressDuration = 0.2f;
242  [self addGestureRecognizer:longPress];
243 }
static const CGFloat kCalendarViewDayFontSize
Definition: CalendarView.m:43
static const CGFloat kCalendarViewHeaderFontSize
Definition: CalendarView.m:44
static const CGFloat kCalendarViewYearCellWidth
Definition: CalendarView.m:26
static const CGFloat kCalendarViewDayCellWidth
Definition: CalendarView.m:16
static const CGFloat kCalendarViewDayCellHeight
Definition: CalendarView.m:17
static const CGFloat kCalendarViewMonthCellHeight
Definition: CalendarView.m:21
static const CGFloat kCalendarViewYearCellHeight
Definition: CalendarView.m:27
static NSString *const kCalendarViewDefaultFont
Definition: CalendarView.m:42
static const CGFloat kCalendarViewMonthCellWidth
Definition: CalendarView.m:20

◆ initWithFrame:()

- (instancetype) initWithFrame: (CGRect)  frame
implementation

Definition at line 154 of file CalendarView.m.

154  :(CGRect)frame
155 {
156  self = [super initWithFrame:frame];
157  if (self) {
158  [self initProperties];
159  [self setup];
160  }
161  return self;
162 }

◆ initWithPosition:y:()

- (instancetype) initWithPosition: (CGFloat)  x
y: (CGFloat)  y 

Definition at line 144 of file CalendarView.m.

144  :(CGFloat)x y:(CGFloat)y
145 {
148 
149  self = [self initWithFrame:CGRectMake(x, y, width, height)];
150 
151  return self;
152 }
static const CGFloat kCalendarViewDayCellWidth
Definition: CalendarView.m:16
static const CGFloat kCalendarViewDayCellOffset
Definition: CalendarView.m:18
static const NSInteger kCalendarViewDaysInWeek
Definition: CalendarView.m:46
static const CGFloat kCalendarViewDayCellHeight
Definition: CalendarView.m:17
static const CGFloat kCalendarViewDaysYOffset
Definition: CalendarView.m:40
static const NSInteger kCalendarViewMaxLinesCount
Definition: CalendarView.m:48

◆ leftSwipe:()

- (void) leftSwipe: (UISwipeGestureRecognizer *)  recognizer
implementation

Definition at line 989 of file CalendarView.m.

989  :(UISwipeGestureRecognizer *)recognizer
990 {
991  [self advanceCalendarContentsWithEvent:CalendarEventSwipeLeft];
992 }

◆ longPress:()

- (void) longPress: (UILongPressGestureRecognizer *)  press
implementation

Definition at line 1094 of file CalendarView.m.

1094  :(UILongPressGestureRecognizer *) press{
1095  //TODO: create start rect and with another tap select the end section
1096  NSSet *key = [press valueForKey:@"activeTouches"];
1097  if (key.count == 0) {
1098  return;
1099  }
1100 
1101  NSInteger day = 0;
1102  CGPoint touchPoint = [press locationInView:self];
1103 
1104  CalendarViewRect *rectWasTapped = nil;
1105 
1106  if (type == CalendarViewTypeYear){
1107  rectWasTapped = [self checkPoint:touchPoint inArray:yearRects];
1108  if (startRangeYear == 0) {
1109  startRangeDay = 1;
1110  startRangeMonth = 1;
1111  startRangeYear = rectWasTapped.value;
1112  } else {
1113  endRangeMonth = 12;
1114  if (startRangeYear > rectWasTapped.value) {
1116  startRangeYear = rectWasTapped.value;
1117  } else {
1118  endRangeYear = rectWasTapped.value;
1119  }
1120  endRangeDay = [self getLastDayOfMonth:endRangeMonth year:endRangeYear];
1121  }
1122  } else if (type == CalendarViewTypeMonth) {
1123  rectWasTapped = [self checkPoint:touchPoint inArray:monthRects];
1124 
1125  if (startRangeMonth == 0) {
1126  startRangeDay = 1;
1127  startRangeMonth = rectWasTapped.value;
1129  } else {
1131  if (startRangeMonth > rectWasTapped.value) {
1133  startRangeMonth = rectWasTapped.value;
1134  } else {
1135  endRangeMonth = rectWasTapped.value;
1136  }
1137  endRangeDay = [self getLastDayOfMonth:endRangeMonth year:endRangeYear];
1138  }
1139  } else if (type == CalendarViewTypeDay) {
1140  rectWasTapped = [self checkPoint:touchPoint inArray:_dayRects];
1141  if (rectWasTapped) {
1142  day = rectWasTapped.value;
1143  if (startRangeDay == 0 && startRangeMonth == 0 && startRangeYear == 0) {
1144  startRangeDay = day;
1147  } else {
1148  if (day > startRangeDay && currentMonth >= startRangeMonth && currentYear >= startRangeYear) {
1149  endRangeDay = day;
1152  } else {
1156 
1157  startRangeDay = day;
1160  }
1161  }
1162  }
1163  }
1164 
1165  startDate = [self generateDateWithDay:startRangeDay month:startRangeMonth year:startRangeYear];
1166  if (endRangeYear > 0) {
1167  endDate = [self generateDateWithDay:endRangeDay month:endRangeMonth year:endRangeYear];
1168  }
1169 
1170  [self selectRangeOfCalendar];
1171  [self setNeedsDisplay];
1172 }
NSDate * startDate
Definition: CalendarView.m:86
NSInteger startRangeYear
Definition: CalendarView.m:84
NSInteger currentMonth
Definition: CalendarView.m:67
NSInteger startRangeMonth
Definition: CalendarView.m:83
NSInteger endRangeMonth
Definition: CalendarView.m:89
NSInteger value
Definition: CalendarView.h:41
NSInteger currentYear
Definition: CalendarView.m:68
NSInteger startRangeDay
Definition: CalendarView.m:82
NSDate * endDate
Definition: CalendarView.m:92
NSInteger endRangeDay
Definition: CalendarView.m:88
NSInteger endRangeYear
Definition: CalendarView.m:90

◆ pinch:()

- (void) pinch: (UIPinchGestureRecognizer *)  recognizer
implementation

Definition at line 999 of file CalendarView.m.

999  :(UIPinchGestureRecognizer *)recognizer
1000 {
1001  if (recognizer.state == UIGestureRecognizerStateEnded) {
1002  NSInteger t = type;
1003  if (recognizer.velocity < 0) {
1004  event = CalendarEventPinchIn;
1005  if (t - 1 >= minType) {
1006  --t;
1007  }
1008  }
1009  else {
1010  event = CalendarEventPinchOut;
1011  if (t + 1 < CalendarViewTypeCount) {
1012  ++t;
1013  }
1014  }
1015 
1016  if (t != type) {
1017  type = t;
1018  [self fade];
1019  }
1020  }
1021 }
NSInteger type
Definition: CalendarView.m:61

◆ refresh()

- (void) refresh

Definition at line 327 of file CalendarView.m.

328 {
329  NSDate *now = [NSDate date];
330  [self setCurrentDate:now];
331 
332  if (self.calendarIdentifier == NSCalendarIdentifierPersian) {
333  [self generatePersianDayRects];
334  } else {
335  [self generateDayRects];
336  }
337  [self generateMonthRects];
338  [self generateYearRects];
339 }
NSCalendarIdentifier calendarIdentifier
Definition: CalendarView.h:100

◆ rewindCalendarContents()

- (void) rewindCalendarContents

Definition at line 898 of file CalendarView.m.

899 {
900  [self rewindCalendarContentsWithEvent:CalendarEventNone];
901 }

◆ rewindCalendarContentsWithEvent:()

- (void) rewindCalendarContentsWithEvent: (CalendarEvent)  eventType
implementation

Definition at line 945 of file CalendarView.m.

945  :(CalendarEvent)eventType
946 {
947  event = eventType;
948 
949  switch (type) {
950  case CalendarViewTypeDay:
951  {
952  if (currentMonth == 1) {
954  --currentYear;
955  }
956  else {
957  --currentMonth;
958  }
959 
960  if (self.calendarIdentifier == NSCalendarIdentifierPersian) {
961  [self generatePersianDayRects];
962  } else {
963  [self generateDayRects];
964  }
965  }
966  break;
967  case CalendarViewTypeMonth:
968  {
969  --currentYear;
970  }
971  break;
972  case CalendarViewTypeYear:
973  {
975  [self generateYearRects];
976  }
977  break;
978 
979  default:
980  break;
981  }
982 
983  [self changeDateEvent];
984  [self fade];
985 }
NSInteger currentMonth
Definition: CalendarView.m:67
NSInteger currentYear
Definition: CalendarView.m:68
static const NSInteger kCalendarViewMonthInYear
Definition: CalendarView.m:47
static const NSInteger kCalendarViewYearsAround
Definition: CalendarView.m:30
NSCalendarIdentifier calendarIdentifier
Definition: CalendarView.h:100

◆ rightSwipe:()

- (void) rightSwipe: (UISwipeGestureRecognizer *)  recognizer
implementation

Definition at line 994 of file CalendarView.m.

994  :(UISwipeGestureRecognizer *)recognizer
995 {
996  [self rewindCalendarContentsWithEvent:CalendarEventSwipeRight];
997 }

◆ selectRangeOfCalendar()

- (void) selectRangeOfCalendar
implementation

Definition at line 885 of file CalendarView.m.

885  {
886  if (_calendarDelegate && [_calendarDelegate respondsToSelector:@selector(didSelectRangeForStartDate:andEndDate:)]) {
887  [_calendarDelegate didSelectRangeForStartDate:startDate andEndDate:endDate];
888  }
889 }

◆ setCalendarIdentifier:()

- (void) setCalendarIdentifier: (NSCalendarIdentifier)  calendarIdentifier
implementation

Definition at line 296 of file CalendarView.m.

296  :(NSCalendarIdentifier)calendarIdentifier{
297  _calendarId = calendarIdentifier;
298  if (calendarIdentifier == NSCalendarIdentifierPersian) {
299  self.preferredWeekStartIndex = 0;
300  }
301 }
NSCalendarIdentifier calendarIdentifier
Definition: CalendarView.h:100

◆ setCurrentDate:()

- (void) setCurrentDate: (NSDate *)  date
implementation

Definition at line 343 of file CalendarView.m.

343  :(NSDate *)date
344 {
345  if (date) {
346  NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:self.calendarIdentifier];
347  NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:date];
348  currentDay = [components day];
349  currentMonth = [components month];
350  currentYear = [components year];
351 
352  switch (type) {
353  case CalendarViewTypeDay:
354  if (self.calendarIdentifier == NSCalendarIdentifierPersian) {
355  [self generatePersianDayRects];
356  } else {
357  [self generateDayRects];
358  }
359  break;
360  case CalendarViewTypeYear:
361  [self generateYearRects];
362  break;
363  default:
364  break;
365  }
366 
367  [self fade];
368 
369  _currentDate = date;
370  }
371 }
NSInteger currentMonth
Definition: CalendarView.m:67
NSInteger currentYear
Definition: CalendarView.m:68
NSCalendarIdentifier calendarIdentifier
Definition: CalendarView.h:100
NSInteger currentDay
Definition: CalendarView.m:66

◆ setLocale:()

- (void) setLocale: (NSLocale *)  locale
implementation

Definition at line 310 of file CalendarView.m.

310  :(NSLocale *)locale{
311  _calenderLocale = locale;
312 }
NSLocale * locale
Definition: CalendarView.h:101

◆ setMode:()

- (void) setMode: (NSInteger)  m

Definition at line 267 of file CalendarView.m.

267  :(NSInteger)m
268 {
269  mode = m;
270  switch (mode) {
271  case CalendarModeDefault:
272  {
273  type = CalendarViewTypeDay;
274  minType = CalendarViewTypeDay;
275  }
276  break;
277  case CalendarModeMonthsAndYears:
278  {
279  type = CalendarViewTypeMonth;
280  minType = CalendarViewTypeMonth;
281  }
282  break;
283  case CalendarModeYears:
284  {
285  type = CalendarViewTypeYear;
286  minType = CalendarViewTypeYear;
287  }
288  break;
289 
290  default:
291  break;
292  }
293 }
NSInteger type
Definition: CalendarView.m:61
NSInteger minType
Definition: CalendarView.m:62
NSInteger mode
Definition: CalendarView.m:63

◆ setup()

- (void) setup
implementation

Definition at line 245 of file CalendarView.m.

246 {
247  _dayRects = [[NSMutableArray alloc] init];
248  monthRects = [[NSMutableArray alloc] init];
249  yearRects = [[NSMutableArray alloc] init];
250 
251  yearTitleRect = CGRectMake(0, 0, 0, 0);
252  monthTitleRect = CGRectMake(0, 0, 0, 0);
253 
254  event = CalendarEventNone;
255 
256  NSDate *now = [NSDate date];
257  NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:self.calendarIdentifier];
258  NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:now];
259 
260  todayDay = [components day];
261  todayMonth = [components month];
262  todayYear = [components year];
263 
264  [self refresh];
265 }
CGRect yearTitleRect
Definition: CalendarView.m:78
NSInteger todayYear
Definition: CalendarView.m:72
NSInteger todayMonth
Definition: CalendarView.m:71
CGRect monthTitleRect
Definition: CalendarView.m:79
NSMutableArray * yearRects
Definition: CalendarView.m:76
NSInteger todayDay
Definition: CalendarView.m:70
NSMutableArray * monthRects
Definition: CalendarView.m:75

◆ tap:()

- (void) tap: (UITapGestureRecognizer *)  recognizer
implementation

Definition at line 1023 of file CalendarView.m.

1023  :(UITapGestureRecognizer *)recognizer
1024 {
1025  event = CalendarEventTap;
1026  CGPoint touchPoint = [recognizer locationInView:self];
1027 
1028  if (CGRectContainsPoint(yearTitleRect, touchPoint)) {
1029  if (type != CalendarViewTypeYear) {
1030  type = CalendarViewTypeYear;
1031  [self fade];
1032  }
1033  return;
1034  }
1035 
1036  if (CGRectContainsPoint(monthTitleRect, touchPoint)) {
1037  if (type != CalendarViewTypeMonth) {
1038  type = CalendarViewTypeMonth;
1039  [self fade];
1040  }
1041  return;
1042  }
1043 
1044  BOOL hasEvent = NO;
1045  switch (type) {
1046  case CalendarViewTypeDay:
1047  {
1048  hasEvent = [self checkPoint:touchPoint inArray:_dayRects andSetValue:&currentDay];
1049  }
1050  break;
1051  case CalendarViewTypeMonth:
1052  {
1053  hasEvent = [self checkPoint:touchPoint inArray:monthRects andSetValue:&currentMonth];
1054  }
1055  break;
1056  case CalendarViewTypeYear:
1057  {
1058  hasEvent = [self checkPoint:touchPoint inArray:yearRects andSetValue:&currentYear];
1059  }
1060  break;
1061 
1062  default:
1063  break;
1064  }
1065 
1066  if (hasEvent) {
1067  [self changeDateEvent];
1068  [self setNeedsDisplay];
1069  }
1070 }
NSInteger type
Definition: CalendarView.m:61

Member Data Documentation

◆ currentDay

- (NSInteger) currentDay
protected

Definition at line 66 of file CalendarView.m.

◆ currentMonth

- (NSInteger) currentMonth
protected

Definition at line 67 of file CalendarView.m.

◆ currentYear

- (NSInteger) currentYear
protected

Definition at line 68 of file CalendarView.m.

◆ endDate

- (NSDate*) endDate
protected

Definition at line 92 of file CalendarView.m.

◆ endRangeDay

- (NSInteger) endRangeDay
protected

Definition at line 88 of file CalendarView.m.

◆ endRangeDayRect

- (CalendarViewRect*) endRangeDayRect
protected

Definition at line 91 of file CalendarView.m.

◆ endRangeMonth

- (NSInteger) endRangeMonth
protected

Definition at line 89 of file CalendarView.m.

◆ endRangeYear

- (NSInteger) endRangeYear
protected

Definition at line 90 of file CalendarView.m.

◆ event

- (NSInteger) event
protected

Definition at line 64 of file CalendarView.m.

◆ minType

- (NSInteger) minType
protected

Definition at line 62 of file CalendarView.m.

◆ mode

- (NSInteger) mode
protected

Definition at line 63 of file CalendarView.m.

◆ monthRects

- (NSMutableArray*) monthRects
protected

Definition at line 75 of file CalendarView.m.

◆ monthTitleRect

- (CGRect) monthTitleRect
protected

Definition at line 79 of file CalendarView.m.

◆ startDate

- (NSDate*) startDate
protected

Definition at line 86 of file CalendarView.m.

◆ startRangeDay

- (NSInteger) startRangeDay
protected

Definition at line 82 of file CalendarView.m.

◆ startRangeDayRect

- (CalendarViewRect*) startRangeDayRect
protected

Definition at line 85 of file CalendarView.m.

◆ startRangeMonth

- (NSInteger) startRangeMonth
protected

Definition at line 83 of file CalendarView.m.

◆ startRangeYear

- (NSInteger) startRangeYear
protected

Definition at line 84 of file CalendarView.m.

◆ todayDay

- (NSInteger) todayDay
protected

Definition at line 70 of file CalendarView.m.

◆ todayMonth

- (NSInteger) todayMonth
protected

Definition at line 71 of file CalendarView.m.

◆ todayYear

- (NSInteger) todayYear
protected

Definition at line 72 of file CalendarView.m.

◆ type

- (NSInteger) type
protected

Definition at line 61 of file CalendarView.m.

◆ yearRects

- (NSMutableArray*) yearRects
protected

Definition at line 76 of file CalendarView.m.

◆ yearTitleRect

- (CGRect) yearTitleRect
protected

Definition at line 78 of file CalendarView.m.

Property Documentation

◆ bgColor

- (UIColor*) bgColor
readwritenonatomicstrong

Definition at line 80 of file CalendarView.h.

◆ calendarDelegate

- (id<CalendarViewDelegate>) calendarDelegate
readwritenonatomicweak

Definition at line 71 of file CalendarView.h.

◆ calendarId

- (NSCalendarIdentifier) calendarId
readwritenonatomicstrongimplementation

Definition at line 95 of file CalendarView.m.

◆ calendarIdentifier

- (NSCalendarIdentifier) calendarIdentifier
readwritenonatomicstrong

Definition at line 100 of file CalendarView.h.

◆ calenderLocale

- (NSLocale*) calenderLocale
readwritenonatomicstrongimplementation

Definition at line 96 of file CalendarView.m.

◆ currentDate

- (NSDate *) currentDate
readwritenonatomicstrong

Definition at line 72 of file CalendarView.h.

◆ dayCellHeight

- (CGFloat) dayCellHeight
readwritenonatomicassign

Definition at line 84 of file CalendarView.h.

◆ dayCellWidth

- (CGFloat) dayCellWidth
readwritenonatomicassign

Definition at line 83 of file CalendarView.h.

◆ dayFontSize

- (CGFloat) dayFontSize
readwritenonatomicassign

Definition at line 92 of file CalendarView.h.

◆ dayRects

- (NSMutableArray*) dayRects
readwritenonatomicstrong

Definition at line 69 of file CalendarView.h.

◆ fontColor

- (UIColor*) fontColor
readwritenonatomicstrong

Definition at line 75 of file CalendarView.h.

◆ fontHeaderColor

- (UIColor*) fontHeaderColor
readwritenonatomicstrong

Definition at line 76 of file CalendarView.h.

◆ fontName

- (NSString*) fontName
readwritenonatomicstrong

Definition at line 91 of file CalendarView.h.

◆ fontSelectedColor

- (UIColor*) fontSelectedColor
readwritenonatomicstrong

Definition at line 77 of file CalendarView.h.

◆ headerFontSize

- (CGFloat) headerFontSize
readwritenonatomicassign

Definition at line 93 of file CalendarView.h.

◆ locale

- (NSLocale *) locale
readwritenonatomicstrong

Definition at line 101 of file CalendarView.h.

◆ monthCellHeight

- (CGFloat) monthCellHeight
readwritenonatomicassign

Definition at line 86 of file CalendarView.h.

◆ monthCellWidth

- (CGFloat) monthCellWidth
readwritenonatomicassign

Definition at line 85 of file CalendarView.h.

◆ preferredWeekStartIndex

- (NSInteger) preferredWeekStartIndex
readwritenonatomicassign

Definition at line 104 of file CalendarView.h.

◆ selectionColor

- (UIColor*) selectionColor
readwritenonatomicstrong

Definition at line 78 of file CalendarView.h.

◆ shouldMarkSelectedDate

- (BOOL) shouldMarkSelectedDate
readwritenonatomicassign

Definition at line 96 of file CalendarView.h.

◆ shouldMarkToday

- (BOOL) shouldMarkToday
readwritenonatomicassign

Definition at line 97 of file CalendarView.h.

◆ shouldShowHeaders

- (BOOL) shouldShowHeaders
readwritenonatomicassign

Definition at line 98 of file CalendarView.h.

◆ todayColor

- (UIColor*) todayColor
readwritenonatomicstrong

Definition at line 79 of file CalendarView.h.

◆ useVeryShortWeekdaySymbols

- (BOOL) useVeryShortWeekdaySymbols
readwritenonatomicassign

Definition at line 105 of file CalendarView.h.

◆ yearCellHeight

- (CGFloat) yearCellHeight
readwritenonatomicassign

Definition at line 88 of file CalendarView.h.

◆ yearCellWidth

- (CGFloat) yearCellWidth
readwritenonatomicassign

Definition at line 87 of file CalendarView.h.


The documentation for this class was generated from the following files: