From ea595e021ded971f452a64ed0f9edac0dc49b20b Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Tue, 1 Apr 2014 13:03:03 +0800 Subject: [PATCH 1/2] * Make selection be based on touch up instead of touch down, so user can tap, and drag a little to cancel the touch. Makes scroll much easier to trigger. * Highlights tapped day until the touch is cancelled by dragging. --- TimesSquare/TSQCalendarRowCell.m | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/TimesSquare/TSQCalendarRowCell.m b/TimesSquare/TSQCalendarRowCell.m index 0cf087b..2fd3c4f 100644 --- a/TimesSquare/TSQCalendarRowCell.m +++ b/TimesSquare/TSQCalendarRowCell.m @@ -56,7 +56,10 @@ - (void)createDayButtons; NSMutableArray *dayButtons = [NSMutableArray arrayWithCapacity:self.daysInWeek]; for (NSUInteger index = 0; index < self.daysInWeek; index++) { UIButton *button = [[UIButton alloc] initWithFrame:self.contentView.bounds]; - [button addTarget:self action:@selector(dateButtonPressed:) forControlEvents:UIControlEventTouchDown]; + [button addTarget:self action:@selector(dateButtonPressedDown:) forControlEvents:UIControlEventTouchDown]; + [button addTarget:self action:@selector(dateButtonPressedDragExit:) forControlEvents:UIControlEventTouchDragExit]; + [button addTarget:self action:@selector(dateButtonPressedCancelled:) forControlEvents:UIControlEventTouchCancel]; + [button addTarget:self action:@selector(dateButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; [dayButtons addObject:button]; [self.contentView addSubview:button]; [self configureButton:button]; @@ -181,6 +184,18 @@ - (void)setBottomRow:(BOOL)bottomRow; [self setNeedsLayout]; } +- (void)resetDateButtonDisplay:(UIButton*)aButton; +{ + ((UIButton*)aButton).backgroundColor = nil; + [(UIButton*)aButton setTitleColor:self.textColor forState:UIControlStateNormal]; +} + +- (void)markDateButtonSelected:(UIButton*)aButton; +{ + ((UIButton*)aButton).backgroundColor = [UIColor darkGrayColor]; + [(UIButton*)aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; +} + - (IBAction)dateButtonPressed:(id)sender; { NSDateComponents *offset = [NSDateComponents new]; @@ -189,6 +204,21 @@ - (IBAction)dateButtonPressed:(id)sender; self.calendarView.selectedDate = selectedDate; } +- (IBAction)dateButtonPressedDown:(id)sender; +{ + [self markDateButtonSelected:sender]; +} + +- (IBAction)dateButtonPressedDragExit:(id)sender; +{ + [self resetDateButtonDisplay:sender]; +} + +- (IBAction)dateButtonPressedCancelled:(id)sender; +{ + [self resetDateButtonDisplay:sender]; +} + - (IBAction)todayButtonPressed:(id)sender; { NSDateComponents *offset = [NSDateComponents new]; From 95c0b38ea3a1a882ba3aca93ace8339bd76266bd Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Thu, 3 Apr 2014 11:20:25 +0800 Subject: [PATCH 2/2] Fix: more consistent method names and remove unnecessary casts. --- TimesSquare/TSQCalendarRowCell.m | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/TimesSquare/TSQCalendarRowCell.m b/TimesSquare/TSQCalendarRowCell.m index 2fd3c4f..a3d4587 100644 --- a/TimesSquare/TSQCalendarRowCell.m +++ b/TimesSquare/TSQCalendarRowCell.m @@ -56,10 +56,10 @@ - (void)createDayButtons; NSMutableArray *dayButtons = [NSMutableArray arrayWithCapacity:self.daysInWeek]; for (NSUInteger index = 0; index < self.daysInWeek; index++) { UIButton *button = [[UIButton alloc] initWithFrame:self.contentView.bounds]; - [button addTarget:self action:@selector(dateButtonPressedDown:) forControlEvents:UIControlEventTouchDown]; - [button addTarget:self action:@selector(dateButtonPressedDragExit:) forControlEvents:UIControlEventTouchDragExit]; - [button addTarget:self action:@selector(dateButtonPressedCancelled:) forControlEvents:UIControlEventTouchCancel]; - [button addTarget:self action:@selector(dateButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; + [button addTarget:self action:@selector(dateButtonTouchDown:) forControlEvents:UIControlEventTouchDown]; + [button addTarget:self action:@selector(dateButtonTouchDragExit:) forControlEvents:UIControlEventTouchDragExit]; + [button addTarget:self action:@selector(dateButtonTouchCancel:) forControlEvents:UIControlEventTouchCancel]; + [button addTarget:self action:@selector(dateButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside]; [dayButtons addObject:button]; [self.contentView addSubview:button]; [self configureButton:button]; @@ -186,17 +186,17 @@ - (void)setBottomRow:(BOOL)bottomRow; - (void)resetDateButtonDisplay:(UIButton*)aButton; { - ((UIButton*)aButton).backgroundColor = nil; - [(UIButton*)aButton setTitleColor:self.textColor forState:UIControlStateNormal]; + aButton.backgroundColor = nil; + [aButton setTitleColor:self.textColor forState:UIControlStateNormal]; } - (void)markDateButtonSelected:(UIButton*)aButton; { - ((UIButton*)aButton).backgroundColor = [UIColor darkGrayColor]; - [(UIButton*)aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + aButton.backgroundColor = [UIColor darkGrayColor]; + [aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; } -- (IBAction)dateButtonPressed:(id)sender; +- (IBAction)dateButtonTouchUpInside:(id)sender; { NSDateComponents *offset = [NSDateComponents new]; offset.day = [self.dayButtons indexOfObject:sender]; @@ -204,17 +204,17 @@ - (IBAction)dateButtonPressed:(id)sender; self.calendarView.selectedDate = selectedDate; } -- (IBAction)dateButtonPressedDown:(id)sender; +- (IBAction)dateButtonTouchDown:(id)sender; { [self markDateButtonSelected:sender]; } -- (IBAction)dateButtonPressedDragExit:(id)sender; +- (IBAction)dateButtonTouchDragExit:(id)sender; { [self resetDateButtonDisplay:sender]; } -- (IBAction)dateButtonPressedCancelled:(id)sender; +- (IBAction)dateButtonTouchCancel:(id)sender; { [self resetDateButtonDisplay:sender]; }