From 1ad07998033cb75485c0f7743facb0c796e24de8 Mon Sep 17 00:00:00 2001 From: Jeroen Houtzager Date: Sat, 5 Oct 2013 19:01:41 +0200 Subject: [PATCH 1/2] Removed first day of week references; will take reference from locale --- Examples/Calendar/CKViewController.m | 2 +- Source/CKCalendarView.h | 9 +-------- Source/CKCalendarView.m | 26 +++++--------------------- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/Examples/Calendar/CKViewController.m b/Examples/Calendar/CKViewController.m index 9d50374..5311a81 100644 --- a/Examples/Calendar/CKViewController.m +++ b/Examples/Calendar/CKViewController.m @@ -17,7 +17,7 @@ @implementation CKViewController - (id)init { self = [super init]; if (self) { - CKCalendarView *calendar = [[CKCalendarView alloc] initWithStartDay:startMonday]; + CKCalendarView *calendar = [[CKCalendarView alloc] init]; self.calendar = calendar; calendar.delegate = self; diff --git a/Source/CKCalendarView.h b/Source/CKCalendarView.h index 4615c5a..a2c6d8d 100644 --- a/Source/CKCalendarView.h +++ b/Source/CKCalendarView.h @@ -26,17 +26,10 @@ @end -typedef enum { - startSunday = 1, - startMonday = 2, -} CKCalendarStartDay; - @interface CKCalendarView : UIView -- (id)initWithStartDay:(CKCalendarStartDay)firstDay; -- (id)initWithStartDay:(CKCalendarStartDay)firstDay frame:(CGRect)frame; +- (id)initWithFrame:(CGRect)frame; -@property (nonatomic) CKCalendarStartDay calendarStartDay; @property (nonatomic, strong) NSLocale *locale; @property (nonatomic, readonly) NSArray *datesShowing; diff --git a/Source/CKCalendarView.m b/Source/CKCalendarView.m index e79e5ac..6acf959 100644 --- a/Source/CKCalendarView.m +++ b/Source/CKCalendarView.m @@ -126,14 +126,10 @@ @implementation CKCalendarView @dynamic locale; - (id)init { - return [self initWithStartDay:startSunday]; + return [self initWithFrame:CGRectMake(0, 0, 320, 320)]; } -- (id)initWithStartDay:(CKCalendarStartDay)firstDay { - return [self initWithStartDay:firstDay frame:CGRectMake(0, 0, 320, 320)]; -} - -- (void)_init:(CKCalendarStartDay)firstDay { +- (void)_init { self.calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; [self.calendar setLocale:[NSLocale currentLocale]]; @@ -143,7 +139,6 @@ - (void)_init:(CKCalendarStartDay)firstDay { [self.dateFormatter setTimeStyle:NSDateFormatterNoStyle]; self.dateFormatter.dateFormat = @"LLLL yyyy"; - self.calendarStartDay = firstDay; self.onlyShowCurrentMonth = YES; self.adaptHeightToNumberOfWeeksInMonth = YES; @@ -222,22 +217,18 @@ - (void)_init:(CKCalendarStartDay)firstDay { [self layoutSubviews]; // TODO: this is a hack to get the first month to show properly } -- (id)initWithStartDay:(CKCalendarStartDay)firstDay frame:(CGRect)frame { +- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { - [self _init:firstDay]; + [self _init]; } return self; } -- (id)initWithFrame:(CGRect)frame { - return [self initWithStartDay:startSunday frame:frame]; -} - - (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { - [self _init:startSunday]; + [self _init]; } return self; } @@ -347,13 +338,6 @@ - (void)_updateDayOfWeekLabels { } } -- (void)setCalendarStartDay:(CKCalendarStartDay)calendarStartDay { - _calendarStartDay = calendarStartDay; - [self.calendar setFirstWeekday:self.calendarStartDay]; - [self _updateDayOfWeekLabels]; - [self setNeedsLayout]; -} - - (void)setLocale:(NSLocale *)locale { [self.dateFormatter setLocale:locale]; [self _updateDayOfWeekLabels]; From 7bcd1bb9881575616791e60cc1bd940e260803be Mon Sep 17 00:00:00 2001 From: Jeroen Houtzager Date: Sat, 5 Oct 2013 21:53:15 +0200 Subject: [PATCH 2/2] Fixed warning --- Source/CKCalendarView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CKCalendarView.m b/Source/CKCalendarView.m index 6acf959..8a3399e 100644 --- a/Source/CKCalendarView.m +++ b/Source/CKCalendarView.m @@ -79,7 +79,7 @@ - (void)setDate:(NSDate *)date { _date = date; if (date) { NSDateComponents *comps = [self.calendar components:NSDayCalendarUnit|NSMonthCalendarUnit fromDate:date]; - [self setTitle:[NSString stringWithFormat:@"%d", comps.day] forState:UIControlStateNormal]; + [self setTitle:[NSString stringWithFormat:@"%ld", (long)comps.day] forState:UIControlStateNormal]; } else { [self setTitle:@"" forState:UIControlStateNormal]; }