Skip to content

Commit

Permalink
Add initProperties method for calling in init and first time
Browse files Browse the repository at this point in the history
Move code from Setup method and use in new method
  • Loading branch information
Husseinhj committed Nov 7, 2017
1 parent 5a60627 commit 8795db4
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions ios_calendar/Sources/CalendarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ - (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initProperties];
[self setup];
}
return self;
Expand All @@ -149,7 +150,7 @@ - (instancetype)initWithFrame:(CGRect)frame
- (void)awakeFromNib
{
[super awakeFromNib];

[self initProperties];
[self setup];
}

Expand All @@ -165,26 +166,26 @@ - (void)dealloc

#pragma mark - Setup

- (void)setup
{
- (void) initProperties{
self.dayCellWidth = kCalendarViewDayCellWidth;
self.dayCellHeight = kCalendarViewDayCellHeight;
self.monthCellWidth = kCalendarViewMonthCellWidth;
self.monthCellHeight = kCalendarViewMonthCellHeight;
self.yearCellWidth = kCalendarViewYearCellWidth;
self.yearCellHeight = kCalendarViewYearCellHeight;

self.fontName = kCalendarViewDefaultFont;
self.dayFontSize = kCalendarViewDayFontSize;
self.headerFontSize = kCalendarViewHeaderFontSize;

dayRects = [[NSMutableArray alloc] init];
monthRects = [[NSMutableArray alloc] init];
yearRects = [[NSMutableArray alloc] init];

yearTitleRect = CGRectMake(0, 0, 0, 0);
monthTitleRect = CGRectMake(0, 0, 0, 0);
self.preferredWeekStartIndex = 1; // This is Monday, from [dateFormatter shortWeekdaySymbols]
if (!_fontName) {
self.fontName = kCalendarViewDefaultFont;
}
if (!_dayFontSize) {
self.dayFontSize = kCalendarViewDayFontSize;
}
if (!_headerFontSize) {
self.headerFontSize = kCalendarViewHeaderFontSize;
}

[self setMode:CalendarModeDefault];
self.fontColor = [UIColor blackColor];
self.fontHeaderColor = [UIColor redColor];
self.fontSelectedColor = [UIColor whiteColor];
Expand All @@ -197,24 +198,6 @@ - (void)setup
self.shouldMarkToday = NO;
self.shouldShowHeaders = NO;

event = CalendarEventNone;

[self setMode:CalendarModeDefault];

NSDate *now = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:now];

currentDay = [components day];
currentMonth = [components month];
currentYear = [components year];

todayDay = [components day];
todayMonth = [components month];
todayYear = [components year];

preferredWeekStartIndex = 1; // This is Monday, from [dateFormatter shortWeekdaySymbols]

UISwipeGestureRecognizer *left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe:)];
[left setDirection:UISwipeGestureRecognizerDirectionLeft];
[self addGestureRecognizer:left];
Expand All @@ -233,10 +216,32 @@ - (void)setup
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
doubleTap.numberOfTapsRequired = 2;
[self addGestureRecognizer:doubleTap];
}

- (void)setup
{
dayRects = [[NSMutableArray alloc] init];
monthRects = [[NSMutableArray alloc] init];
yearRects = [[NSMutableArray alloc] init];

[self generateDayRects];
[self generateMonthRects];
[self generateYearRects];
yearTitleRect = CGRectMake(0, 0, 0, 0);
monthTitleRect = CGRectMake(0, 0, 0, 0);

event = CalendarEventNone;

NSDate *now = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:self.calendarIdentifier];
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:now];

currentDay = [components day];
currentMonth = [components month];
currentYear = [components year];

todayDay = [components day];
todayMonth = [components month];
todayYear = [components year];

[self refresh];
}

- (void)setMode:(NSInteger)m
Expand Down

0 comments on commit 8795db4

Please sign in to comment.