Today's Menu  Portugal
journal and plan nutrition
CalendarView.m
Go to the documentation of this file.
1 //
2 // CalendarView.m
3 // ios_calendar
4 //
5 // Created by Maxim on 10/7/13.
6 // Copyright (c) 2013 Maxim. All rights reserved.
7 //
8 
9 #import "CalendarView.h"
10 #import "NSDate+CalendarView.h"
11 #import "NSString+CalendarView.h"
12 
13 #import <CoreText/CoreText.h>
14 
15 
16 static const CGFloat kCalendarViewDayCellWidth = 35;
17 static const CGFloat kCalendarViewDayCellHeight = 65; // originally 35;
18 static const CGFloat kCalendarViewDayCellOffset = 5;
19 
20 static const CGFloat kCalendarViewMonthCellWidth = 90;
21 static const CGFloat kCalendarViewMonthCellHeight = 30;
22 static const CGFloat kCalendarViewMonthTitleOffsetY = 50;
23 static const CGFloat kCalendarViewMonthYStep = 60;
24 static const NSInteger kCalendarViewMonthInLine = 3;
25 
26 static const CGFloat kCalendarViewYearCellWidth = 54;
27 static const CGFloat kCalendarViewYearCellHeight = 30;
28 static const CGFloat kCalendarViewYearTitleOffsetY = 50;
29 static const CGFloat kCalendarViewYearYStep = 45;
30 static const NSInteger kCalendarViewYearsAround = 12;
31 static const NSInteger kCalendarViewYearsInLine = 5;
32 
33 static const CGFloat kCalendarViewMonthLabelWidth = 100;
34 static const CGFloat kCalendarViewMonthLabelHeight = 20;
35 
36 static const CGFloat kCalendarViewYearLabelWidth = 60;
37 static const CGFloat kCalendarViewYearLabelHeight = 20;
38 
39 static const CGFloat kCalendarViewWeekDaysYOffset = 30;
40 static const CGFloat kCalendarViewDaysYOffset = 60;
41 
42 static NSString * const kCalendarViewDefaultFont = @"TrebuchetMS";
43 static const CGFloat kCalendarViewDayFontSize = 16;
44 static const CGFloat kCalendarViewHeaderFontSize = 18;
45 
46 static const NSInteger kCalendarViewDaysInWeek = 7;
47 static const NSInteger kCalendarViewMonthInYear = 12;
48 static const NSInteger kCalendarViewMaxLinesCount = 6;
49 
50 static const CGFloat kCalendarViewSelectionRound = 3.0;
51 
52 static const NSTimeInterval kCalendarViewSwipeMonthFadeInTime = 0.2;
53 static const NSTimeInterval kCalendarViewSwipeMonthFadeOutTime = 0.6;
54 
55 @implementation CalendarViewRect;
56 
57 @end
58 
59 @interface CalendarView ()
60 {
61  NSInteger type;
62  NSInteger minType;
63  NSInteger mode;
64  NSInteger event;
65 
66  NSInteger currentDay;
67  NSInteger currentMonth;
68  NSInteger currentYear;
69 
70  NSInteger todayDay;
71  NSInteger todayMonth;
72  NSInteger todayYear;
73 
74  // NSMutableArray *dayRects;
75  NSMutableArray *monthRects;
76  NSMutableArray *yearRects;
77 
78  CGRect yearTitleRect;
80 
81  // Range selection properties
82  NSInteger startRangeDay;
83  NSInteger startRangeMonth;
84  NSInteger startRangeYear;
86  NSDate *startDate;
87 
88  NSInteger endRangeDay;
89  NSInteger endRangeMonth;
90  NSInteger endRangeYear;
92  NSDate *endDate;
93 }
94 
95 @property (nonatomic, strong) NSCalendarIdentifier calendarId;
96 @property (nonatomic, strong) NSLocale *calenderLocale;
97 
98 - (void)setup;
99 
100 - (void)generateDayRects;
101 - (void)generateMonthRects;
102 - (void)generateYearRects;
103 - (CGFloat)getEffectiveWeekDaysYOffset;
104 - (CGFloat)getEffectiveDaysYOffset;
105 - (CGFloat)getEffectiveMonthsYOffset;
106 - (CGFloat)getEffectiveYearsYOffset;
107 
108 - (void)drawCircle:(CGRect)rect toContext:(CGContextRef *)context withColor:(UIColor *)color;
109 - (void)drawRoundedRectangle:(CGRect)rect toContext:(CGContextRef *)context;
110 - (void)drawWeekDays;
111 
112 - (void)leftSwipe:(UISwipeGestureRecognizer *)recognizer;
113 - (void)rightSwipe:(UISwipeGestureRecognizer *)recognizer;
114 - (void)pinch:(UIPinchGestureRecognizer *)recognizer;
115 - (void)tap:(UITapGestureRecognizer *)recognizer;
116 - (void)doubleTap:(UITapGestureRecognizer *)recognizer;
117 
118 - (void)changeDateEvent;
119 
120 - (void)advanceCalendarContentsWithEvent:(CalendarEvent)eventType;
121 - (void)rewindCalendarContentsWithEvent:(CalendarEvent)eventType;
122 
123 - (NSDictionary *)generateAttributes:(NSString *)fontName withFontSize:(CGFloat)fontSize withColor:(UIColor *)color withAlignment:(NSTextAlignment)textAlignment;
124 - (BOOL)checkPoint:(CGPoint)point inArray:(NSMutableArray *)array andSetValue:(NSInteger *)value;
125 - (void)fade;
126 
127 - (void) setCalendarIdentifier:(NSCalendarIdentifier)calendarIdentifier;
128 - (NSCalendarIdentifier) calendarIdentifier;
129 
130 @end
131 
132 @implementation CalendarView
133 
134 @synthesize currentDate = _currentDate;
135 
136 #pragma mark - Initialization
137 
138 - (instancetype)init
139 {
140  self = [self initWithPosition:0.0 y:0.0];
141  return self;
142 }
143 
144 - (instancetype)initWithPosition:(CGFloat)x y:(CGFloat)y
145 {
148 
149  self = [self initWithFrame:CGRectMake(x, y, width, height)];
150 
151  return self;
152 }
153 
154 - (instancetype)initWithFrame:(CGRect)frame
155 {
156  self = [super initWithFrame:frame];
157  if (self) {
158  [self initProperties];
159  [self setup];
160  }
161  return self;
162 }
163 
165 {
166  [super awakeFromNib];
167  [self initProperties];
168  [self setup];
169 }
170 
171 - (void)dealloc
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 }
180 
181 #pragma mark - Setup
182 
183 - (void) initProperties{
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 }
244 
245 - (void)setup
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 }
266 
267 - (void)setMode:(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 }
294 
295 #pragma mark - calendarIdentifier getter/setter methods
296 - (void) setCalendarIdentifier:(NSCalendarIdentifier)calendarIdentifier{
297  _calendarId = calendarIdentifier;
298  if (calendarIdentifier == NSCalendarIdentifierPersian) {
299  self.preferredWeekStartIndex = 0;
300  }
301 }
302 - (NSCalendarIdentifier) calendarIdentifier{
303  if (_calendarId) {
304  return _calendarId;
305  }
306  return NSCalendarIdentifierGregorian;
307 }
308 
309 #pragma mark - locale getter/setter methods
310 - (void) setLocale:(NSLocale *)locale{
311  _calenderLocale = locale;
312 }
313 - (NSLocale *) locale{
314  if (_calenderLocale) {
315  return _calenderLocale;
316  }
317  return [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
318 }
319 
320 #pragma mark - reload
321 
322 - (void) goToToday{
323  [self setup];
324 }
325 #pragma mark - Refresh
326 
327 - (void)refresh
328 {
329  NSDate *now = [NSDate date];
330  [self setCurrentDate:now];
331 
332  if (self.calendarIdentifier == NSCalendarIdentifierPersian) {
334  } else {
335  [self generateDayRects];
336  }
337  [self generateMonthRects];
338  [self generateYearRects];
339 }
340 
341 #pragma mark - Getting, setting current date
342 
343 - (void)setCurrentDate:(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) {
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 }
372 
373 - (NSDate *)currentDate
374 {
375  return [self generateDateWithDay:currentDay month:currentMonth year:currentYear];
376 }
377 
378 /*
379  generateDateComponents
380  Discussion :
381  generate date component for current date and L.A. time zone
382 
383  */
384 - (NSDateComponents *) generateDateComponents{
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 }
397 
398 - (NSDate *) generateDateWithDay:(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 }
410 
411 -(NSInteger) getLastDayOfMonth:(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 }
417 
418 #pragma mark - Generating of rects
419 
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 }
464 
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 }
547 
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 }
575 
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 }
606 
607 # pragma mark - Layout Calculations
608 
610 {
611  if (self.shouldShowHeaders) {
613  } else {
614  return 0;
615  }
616 }
617 
619 {
620  if (self.shouldShowHeaders) {
622  } else {
624  }
625 }
626 
628 {
629  if (self.shouldShowHeaders) {
631  } else {
632  return 0;
633  }
634 }
635 
637 {
638  if (self.shouldShowHeaders) {
640  } else return 0;
641 }
642 
643 #pragma mark - Drawing
644 
645 - (void)drawRect:(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 }
794 
795 - (void)drawCircle:(CGRect)rect toContext:(CGContextRef *)context withColor:(UIColor *)color
796 {
797  CGContextSetFillColorWithColor(*context, color.CGColor);
798  CGContextFillEllipseInRect(*context, rect);
799 }
800 
801 - (void)drawRoundedRectangle:(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 }
818 
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 }
869 
870 #pragma mark - Change date event
871 
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 }
882 
883 #pragma mark - Select range of calendar
884 
886  if (_calendarDelegate && [_calendarDelegate respondsToSelector:@selector(didSelectRangeForStartDate:andEndDate:)]) {
887  [_calendarDelegate didSelectRangeForStartDate:startDate andEndDate:endDate];
888  }
889 }
890 
891 #pragma mark - Advance/Rewind Calendar Contents
892 
894 {
895  [self advanceCalendarContentsWithEvent:CalendarEventNone];
896 }
897 
899 {
900  [self rewindCalendarContentsWithEvent:CalendarEventNone];
901 }
902 
903 - (void)advanceCalendarContentsWithEvent:(CalendarEvent)eventType
904 {
905  event = eventType;
906 
907  switch (type) {
908  case CalendarViewTypeDay:
909  {
911  currentMonth = 1;
912  ++currentYear;
913  }
914  else {
915  ++currentMonth;
916  }
917 
918  if (self.calendarIdentifier == NSCalendarIdentifierPersian) {
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 }
944 
945 - (void)rewindCalendarContentsWithEvent:(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) {
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 }
986 
987 #pragma mark - Gestures
988 
989 - (void)leftSwipe:(UISwipeGestureRecognizer *)recognizer
990 {
991  [self advanceCalendarContentsWithEvent:CalendarEventSwipeLeft];
992 }
993 
994 - (void)rightSwipe:(UISwipeGestureRecognizer *)recognizer
995 {
996  [self rewindCalendarContentsWithEvent:CalendarEventSwipeRight];
997 }
998 
999 - (void)pinch:(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 }
1022 
1023 - (void)tap:(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 }
1071 
1072 - (void)doubleTap:(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 }
1093 
1094 - (void) longPress:(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 {
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 }
1173 #pragma mark - Additional functions
1174 
1175 - (BOOL)checkPoint:(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 }
1183 
1184 - (CalendarViewRect *)checkPoint:(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 }
1192 
1193 - (NSDictionary *)generateAttributes:(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 }
1213 
1214 - (void)fade
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 }
1233 
1234 @end
CGRect yearTitleRect
Definition: CalendarView.m:78
NSInteger event
Definition: CalendarView.m:64
BOOL checkPoint:inArray:andSetValue:(CGPoint point, [inArray] NSMutableArray *array, [andSetValue] NSInteger *value)
CGFloat monthCellHeight
Definition: CalendarView.h:86
NSDate * startDate
Definition: CalendarView.m:86
NSDate * currentDate
Definition: CalendarView.h:72
NSString * str
Definition: CalendarView.h:42
CGFloat getEffectiveMonthsYOffset()
Definition: CalendarView.m:627
void setMode:(NSInteger m)
Definition: CalendarView.m:267
CalendarViewRect * checkPoint:inArray:(CGPoint point, [inArray] NSMutableArray *array)
static const CGFloat kCalendarViewDayFontSize
Definition: CalendarView.m:43
void setCurrentDate:(NSDate *date)
Definition: CalendarView.m:343
UIColor * selectionColor
Definition: CalendarView.h:78
BOOL shouldShowHeaders
Definition: CalendarView.h:98
static const CGFloat kCalendarViewYearLabelWidth
Definition: CalendarView.m:36
instancetype initWithPosition:y:(CGFloat x, [y] CGFloat y)
Definition: CalendarView.m:144
static const CGFloat kCalendarViewHeaderFontSize
Definition: CalendarView.m:44
void advanceCalendarContentsWithEvent:(CalendarEvent eventType)
Definition: CalendarView.m:903
UIColor * bgColor
Definition: CalendarView.h:80
void generateMonthRects()
Definition: CalendarView.m:548
NSInteger todayYear
Definition: CalendarView.m:72
CGFloat getEffectiveDaysYOffset()
Definition: CalendarView.m:618
NSString * fontName
Definition: CalendarView.h:91
CGFloat getEffectiveYearsYOffset()
Definition: CalendarView.m:636
instancetype init()
Definition: CalendarView.m:138
static const NSTimeInterval kCalendarViewSwipeMonthFadeInTime
Definition: CalendarView.m:52
NSInteger preferredWeekStartIndex
Definition: CalendarView.h:104
NSInteger todayMonth
Definition: CalendarView.m:71
NSInteger startRangeYear
Definition: CalendarView.m:84
NSInteger type
Definition: CalendarView.m:61
NSInteger currentMonth
Definition: CalendarView.m:67
void initProperties()
Definition: CalendarView.m:183
CGFloat getEffectiveWeekDaysYOffset()
Definition: CalendarView.m:609
void selectRangeOfCalendar()
Definition: CalendarView.m:885
void drawCircle:toContext:withColor:(CGRect rect, [toContext] CGContextRef *context, [withColor] UIColor *color)
Definition: CalendarView.m:795
void generateDayRects()
Definition: CalendarView.m:420
CGRect monthTitleRect
Definition: CalendarView.m:79
static const CGFloat kCalendarViewMonthTitleOffsetY
Definition: CalendarView.m:22
static const CGFloat kCalendarViewYearCellWidth
Definition: CalendarView.m:26
void generateYearRects()
Definition: CalendarView.m:576
NSInteger minType
Definition: CalendarView.m:62
void advanceCalendarContents()
Definition: CalendarView.m:893
instancetype initWithFrame:(CGRect frame)
Definition: CalendarView.m:154
NSMutableArray * yearRects
Definition: CalendarView.m:76
static const CGFloat kCalendarViewWeekDaysYOffset
Definition: CalendarView.m:39
CGFloat monthCellWidth
Definition: CalendarView.h:85
void awakeFromNib()
Definition: CalendarView.m:164
void generatePersianDayRects()
Definition: CalendarView.m:465
NSInteger startRangeMonth
Definition: CalendarView.m:83
NSLocale * locale
Definition: CalendarView.h:101
void changeDateEvent()
Definition: CalendarView.m:872
static const CGFloat kCalendarViewMonthLabelWidth
Definition: CalendarView.m:33
NSDateComponents * generateDateComponents()
Definition: CalendarView.m:384
NSInteger endRangeMonth
Definition: CalendarView.m:89
CGFloat dayCellWidth
Definition: CalendarView.h:83
NSInteger todayDay
Definition: CalendarView.m:70
static const CGFloat kCalendarViewDayCellWidth
Definition: CalendarView.m:16
void rewindCalendarContentsWithEvent:(CalendarEvent eventType)
Definition: CalendarView.m:945
static const CGFloat kCalendarViewDayCellOffset
Definition: CalendarView.m:18
CalendarViewRect * startRangeDayRect
Definition: CalendarView.m:85
NSInteger value
Definition: CalendarView.h:41
NSInteger currentYear
Definition: CalendarView.m:68
static const CGFloat kCalendarViewYearYStep
Definition: CalendarView.m:29
NSInteger startRangeDay
Definition: CalendarView.m:82
static const NSInteger kCalendarViewDaysInWeek
Definition: CalendarView.m:46
NSDate * endDate
Definition: CalendarView.m:92
static const CGFloat kCalendarViewSelectionRound
Definition: CalendarView.m:50
NSDate * generateDateWithDay:month:year:(NSInteger day, [month] NSInteger month, [year] NSInteger year)
Definition: CalendarView.m:398
static const NSTimeInterval kCalendarViewSwipeMonthFadeOutTime
Definition: CalendarView.m:53
NSMutableArray * monthRects
Definition: CalendarView.m:75
static const CGFloat kCalendarViewDayCellHeight
Definition: CalendarView.m:17
CGFloat yearCellHeight
Definition: CalendarView.h:88
CalendarViewRect * endRangeDayRect
Definition: CalendarView.m:91
static const CGFloat kCalendarViewDaysYOffset
Definition: CalendarView.m:40
void rewindCalendarContents()
Definition: CalendarView.m:898
static const CGFloat kCalendarViewMonthCellHeight
Definition: CalendarView.m:21
CGFloat dayFontSize
Definition: CalendarView.h:92
CGFloat yearCellWidth
Definition: CalendarView.h:87
static const NSInteger kCalendarViewMonthInYear
Definition: CalendarView.m:47
static const NSInteger kCalendarViewYearsInLine
Definition: CalendarView.m:31
NSInteger endRangeDay
Definition: CalendarView.m:88
static const CGFloat kCalendarViewYearTitleOffsetY
Definition: CalendarView.m:28
void drawRoundedRectangle:toContext:(CGRect rect, [toContext] CGContextRef *context)
Definition: CalendarView.m:801
static const CGFloat kCalendarViewYearLabelHeight
Definition: CalendarView.m:37
NSDictionary * generateAttributes:withFontSize:withColor:withAlignment:(NSString *fontName, [withFontSize] CGFloat fontSize, [withColor] UIColor *color, [withAlignment] NSTextAlignment textAlignment)
static const CGFloat kCalendarViewYearCellHeight
Definition: CalendarView.m:27
NSInteger mode
Definition: CalendarView.m:63
NSInteger endRangeYear
Definition: CalendarView.m:90
static const NSInteger kCalendarViewYearsAround
Definition: CalendarView.m:30
static NSString *const kCalendarViewDefaultFont
Definition: CalendarView.m:42
static const NSInteger kCalendarViewMaxLinesCount
Definition: CalendarView.m:48
NSCalendarIdentifier calendarIdentifier
Definition: CalendarView.h:100
NSInteger getLastDayOfMonth:year:(NSInteger month, [year] NSInteger year)
Definition: CalendarView.m:411
static const CGFloat kCalendarViewMonthYStep
Definition: CalendarView.m:23
void drawWeekDays()
Definition: CalendarView.m:819
static const CGFloat kCalendarViewMonthLabelHeight
Definition: CalendarView.m:34
NSInteger currentDay
Definition: CalendarView.m:66
static const CGFloat kCalendarViewMonthCellWidth
Definition: CalendarView.m:20
static const NSInteger kCalendarViewMonthInLine
Definition: CalendarView.m:24