Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/Calendar/CKViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 1 addition & 8 deletions Source/CKCalendarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 6 additions & 22 deletions Source/CKCalendarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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]];

Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand Down