Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add property to enable/disable range selection #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions DSLCalendarView/DSLCalendarDayView.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum {
@property (nonatomic, assign) DSLCalendarDayViewPositionInWeek positionInWeek;
@property (nonatomic, assign) DSLCalendarDayViewSelectionState selectionState;
@property (nonatomic, assign, getter = isInCurrentMonth) BOOL inCurrentMonth;
@property (nonatomic, assign) BOOL isCurrentDay;

@property (nonatomic, strong, readonly) NSDate *dayAsDate;

Expand Down
3 changes: 3 additions & 0 deletions DSLCalendarView/DSLCalendarDayView.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ - (void)drawBackground {
else {
[[UIColor colorWithWhite:225.0/255.0 alpha:1.0] setFill];
}
if(_isCurrentDay) {
[[UIColor colorWithRed:0x08/255.0 green:0x7D/255.0 blue:0xE8/255.0 alpha:1.0] setFill];
}
UIRectFill(self.bounds);
}
else {
Expand Down
18 changes: 18 additions & 0 deletions DSLCalendarView/DSLCalendarMonthView.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ - (void)createDayViews {
dayView.positionInWeek = DSLCalendarDayViewMidWeek;
break;
}

if([self isToday:day]) {
dayView.isCurrentDay = YES;
}

[self.dayViewsDictionary setObject:dayView forKey:[self dayViewKeyForDay:day]];
[self addSubview:dayView];
Expand All @@ -142,6 +146,20 @@ - (void)createDayViews {
self.frame = fullFrame;
}

- (BOOL) isToday:(NSDateComponents*)components {
NSCalendar *calendar = [NSCalendar currentCalendar];
NSInteger comps = (NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit);

NSDateComponents *date2Components = [calendar components:comps fromDate:[NSDate new]];

NSDate *date1 = [calendar dateFromComponents:components];
NSDate *date2 = [calendar dateFromComponents:date2Components];

NSComparisonResult result = [date1 compare:date2];

return result != NSOrderedAscending && result != NSOrderedDescending;
}

- (void)updateDaySelectionStatesForRange:(DSLCalendarRange*)range {
for (DSLCalendarDayView *dayView in self.dayViews) {
if ([range containsDate:dayView.dayAsDate]) {
Expand Down
1 change: 1 addition & 0 deletions DSLCalendarView/DSLCalendarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@property (nonatomic, copy) NSDateComponents *visibleMonth;
@property (nonatomic, strong) DSLCalendarRange *selectedRange;
@property (nonatomic, assign) BOOL showDayCalloutView;
@property (nonatomic, assign) BOOL allowRangeSelect;

+ (Class)monthSelectorViewClass;
+ (Class)monthViewClass;
Expand Down
5 changes: 5 additions & 0 deletions DSLCalendarView/DSLCalendarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
self.draggedOffStartDay = YES;
}
}

if(!self.allowRangeSelect) {
self.draggingStartDay = touchedView.day;
self.selectedRange = [[DSLCalendarRange alloc] initWithStartDay:touchedView.day endDay:touchedView.day];
}

[self positionCalloutViewForDayView:touchedView];
}
Expand Down
1 change: 1 addition & 0 deletions Example/DSLCalendarViewExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ - (void)viewDidLoad
// Do any additional setup after loading the view, typically from a nib.

self.calendarView.delegate = self;
self.calendarView.allowRangeSelect = YES;
}

- (void)viewDidUnload
Expand Down