From ca1313a99942d4e7a6e5093464027c95a675ab14 Mon Sep 17 00:00:00 2001 From: Simon Booth Date: Fri, 10 May 2013 15:08:28 +0100 Subject: [PATCH 1/4] Show an event marker for particular dates --- TimesSquare.xcodeproj/project.pbxproj | 8 +++ TimesSquare/TSQCalendarRowButton.h | 26 ++++++++ TimesSquare/TSQCalendarRowButton.m | 76 ++++++++++++++++++++++++ TimesSquare/TSQCalendarRowCell.m | 31 +++++----- TimesSquare/TSQCalendarView.h | 19 ++++++ TimesSquare/TSQCalendarView.m | 10 ++++ TimesSquareTestApp/TSQTAViewController.m | 11 +++- 7 files changed, 166 insertions(+), 15 deletions(-) create mode 100644 TimesSquare/TSQCalendarRowButton.h create mode 100644 TimesSquare/TSQCalendarRowButton.m diff --git a/TimesSquare.xcodeproj/project.pbxproj b/TimesSquare.xcodeproj/project.pbxproj index bb0983a..aa6cae0 100644 --- a/TimesSquare.xcodeproj/project.pbxproj +++ b/TimesSquare.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ EFD8DE6F167AF78600F87FBE /* TSQCalendarMonthHeaderCell.h in Headers */ = {isa = PBXBuildFile; fileRef = A8068088167010030071C71E /* TSQCalendarMonthHeaderCell.h */; settings = {ATTRIBUTES = (Public, ); }; }; EFD8DE70167AF78C00F87FBE /* TSQCalendarRowCell.h in Headers */ = {isa = PBXBuildFile; fileRef = A806808A167010030071C71E /* TSQCalendarRowCell.h */; settings = {ATTRIBUTES = (Public, ); }; }; EFD8DE71167AF79000F87FBE /* TSQCalendarView.h in Headers */ = {isa = PBXBuildFile; fileRef = A806808C167010030071C71E /* TSQCalendarView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + F6C9C449173D29C3004EA826 /* TSQCalendarRowButton.h in Headers */ = {isa = PBXBuildFile; fileRef = F6C9C447173D29C3004EA826 /* TSQCalendarRowButton.h */; }; + F6C9C44A173D29C3004EA826 /* TSQCalendarRowButton.m in Sources */ = {isa = PBXBuildFile; fileRef = F6C9C448173D29C3004EA826 /* TSQCalendarRowButton.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -48,6 +50,8 @@ A806808C167010030071C71E /* TSQCalendarView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSQCalendarView.h; sourceTree = ""; }; A806808D167010030071C71E /* TSQCalendarView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSQCalendarView.m; sourceTree = ""; }; A806809E167012980071C71E /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + F6C9C447173D29C3004EA826 /* TSQCalendarRowButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSQCalendarRowButton.h; sourceTree = ""; }; + F6C9C448173D29C3004EA826 /* TSQCalendarRowButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSQCalendarRowButton.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -99,6 +103,8 @@ A8068087167010030071C71E /* TSQCalendarCell.m */, A8068088167010030071C71E /* TSQCalendarMonthHeaderCell.h */, A8068089167010030071C71E /* TSQCalendarMonthHeaderCell.m */, + F6C9C447173D29C3004EA826 /* TSQCalendarRowButton.h */, + F6C9C448173D29C3004EA826 /* TSQCalendarRowButton.m */, A806808A167010030071C71E /* TSQCalendarRowCell.h */, A806808B167010030071C71E /* TSQCalendarRowCell.m */, A806808C167010030071C71E /* TSQCalendarView.h */, @@ -128,6 +134,7 @@ EFD8DE6F167AF78600F87FBE /* TSQCalendarMonthHeaderCell.h in Headers */, EFD8DE70167AF78C00F87FBE /* TSQCalendarRowCell.h in Headers */, EFD8DE71167AF79000F87FBE /* TSQCalendarView.h in Headers */, + F6C9C449173D29C3004EA826 /* TSQCalendarRowButton.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -205,6 +212,7 @@ A8068090167010030071C71E /* TSQCalendarMonthHeaderCell.m in Sources */, A8068092167010030071C71E /* TSQCalendarRowCell.m in Sources */, A8068094167010030071C71E /* TSQCalendarView.m in Sources */, + F6C9C44A173D29C3004EA826 /* TSQCalendarRowButton.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/TimesSquare/TSQCalendarRowButton.h b/TimesSquare/TSQCalendarRowButton.h new file mode 100644 index 0000000..d7fd88f --- /dev/null +++ b/TimesSquare/TSQCalendarRowButton.h @@ -0,0 +1,26 @@ +// +// TSQCalendarButton.h +// TimesSquare +// +// Created by Simon Booth on 10/05/2013. +// Licensed to Square, Inc. under one or more contributor license agreements. +// See the LICENSE file distributed with this work for the terms under +// which Square, Inc. licenses this file to you. + + +#import + +/** The `TSQCalendarRowButton` class is a button that represents single day in the calendar. + + The button contains an additional label which is used to display an event marker. + */ +@interface TSQCalendarRowButton : UIButton + +/** A label used to display an event marker + + The marker is shown using the bullet character '•' + + */ +@property (nonatomic, strong, readonly) UILabel *subtitleLabel; + +@end diff --git a/TimesSquare/TSQCalendarRowButton.m b/TimesSquare/TSQCalendarRowButton.m new file mode 100644 index 0000000..4e1bcca --- /dev/null +++ b/TimesSquare/TSQCalendarRowButton.m @@ -0,0 +1,76 @@ +// +// TSQCalendarButton.m +// TimesSquare +// +// Created by Simon Booth on 10/05/2013. +// Licensed to Square, Inc. under one or more contributor license agreements. +// See the LICENSE file distributed with this work for the terms under +// which Square, Inc. licenses this file to you. + +#import "TSQCalendarRowButton.h" + + +@implementation TSQCalendarRowButton + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) + { + self.titleLabel.font = [UIFont boldSystemFontOfSize:19.f]; + self.adjustsImageWhenDisabled = NO; + [self setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal]; + + _subtitleLabel = [[UILabel alloc] init]; + _subtitleLabel.backgroundColor = [UIColor clearColor]; + _subtitleLabel.textAlignment = UITextAlignmentCenter; + [self addSubview:_subtitleLabel]; + + [self updateSubtitleLabel]; + } + return self; +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + CGRect subtitleFrame = self.bounds; + subtitleFrame.origin.y = subtitleFrame.size.height - 15; + subtitleFrame.size.height = 15; + self.subtitleLabel.frame = subtitleFrame; +} + +- (void)updateSubtitleLabel +{ + self.subtitleLabel.font = self.titleLabel.font; + self.subtitleLabel.textColor = self.currentTitleColor; + self.subtitleLabel.shadowColor = self.currentTitleShadowColor; + self.subtitleLabel.shadowOffset = self.titleLabel.shadowOffset; +} + +- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state +{ + [super setTitleShadowColor:color forState:state]; + [self updateSubtitleLabel]; +} + +- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state +{ + [super setTitleColor:color forState:state]; + [self updateSubtitleLabel]; +} + +- (void)setHighlighted:(BOOL)highlighted +{ + [super setHighlighted:highlighted]; + [self updateSubtitleLabel]; +} + +- (void)setSelected:(BOOL)selected +{ + [super setSelected:selected]; + [self updateSubtitleLabel]; +} + +@end diff --git a/TimesSquare/TSQCalendarRowCell.m b/TimesSquare/TSQCalendarRowCell.m index 312a7f2..4e3cebd 100644 --- a/TimesSquare/TSQCalendarRowCell.m +++ b/TimesSquare/TSQCalendarRowCell.m @@ -9,14 +9,14 @@ #import "TSQCalendarRowCell.h" #import "TSQCalendarView.h" - +#import "TSQCalendarRowButton.h" @interface TSQCalendarRowCell () @property (nonatomic, strong) NSArray *dayButtons; @property (nonatomic, strong) NSArray *notThisMonthButtons; -@property (nonatomic, strong) UIButton *todayButton; -@property (nonatomic, strong) UIButton *selectedButton; +@property (nonatomic, strong) TSQCalendarRowButton *todayButton; +@property (nonatomic, strong) TSQCalendarRowButton *selectedButton; @property (nonatomic, assign) NSInteger indexOfTodayButton; @property (nonatomic, assign) NSInteger indexOfSelectedButton; @@ -42,20 +42,18 @@ - (id)initWithCalendar:(NSCalendar *)calendar reuseIdentifier:(NSString *)reuseI return self; } -- (void)configureButton:(UIButton *)button; +- (void)configureButton:(TSQCalendarRowButton *)button; { - button.titleLabel.font = [UIFont boldSystemFontOfSize:19.f]; button.titleLabel.shadowOffset = self.shadowOffset; - button.adjustsImageWhenDisabled = NO; [button setTitleColor:self.textColor forState:UIControlStateNormal]; - [button setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal]; + button.subtitleLabel.shadowOffset = self.shadowOffset; } - (void)createDayButtons; { NSMutableArray *dayButtons = [NSMutableArray arrayWithCapacity:self.daysInWeek]; for (NSUInteger index = 0; index < self.daysInWeek; index++) { - UIButton *button = [[UIButton alloc] initWithFrame:self.contentView.bounds]; + TSQCalendarRowButton *button = [[TSQCalendarRowButton alloc] initWithFrame:self.contentView.bounds]; [button addTarget:self action:@selector(dateButtonPressed:) forControlEvents:UIControlEventTouchDown]; [dayButtons addObject:button]; [self.contentView addSubview:button]; @@ -69,7 +67,7 @@ - (void)createNotThisMonthButtons; { NSMutableArray *notThisMonthButtons = [NSMutableArray arrayWithCapacity:self.daysInWeek]; for (NSUInteger index = 0; index < self.daysInWeek; index++) { - UIButton *button = [[UIButton alloc] initWithFrame:self.contentView.bounds]; + TSQCalendarRowButton *button = [[TSQCalendarRowButton alloc] initWithFrame:self.contentView.bounds]; [notThisMonthButtons addObject:button]; [self.contentView addSubview:button]; [self configureButton:button]; @@ -84,7 +82,7 @@ - (void)createNotThisMonthButtons; - (void)createTodayButton; { - self.todayButton = [[UIButton alloc] initWithFrame:self.contentView.bounds]; + self.todayButton = [[TSQCalendarRowButton alloc] initWithFrame:self.contentView.bounds]; [self.contentView addSubview:self.todayButton]; [self configureButton:self.todayButton]; [self.todayButton addTarget:self action:@selector(todayButtonPressed:) forControlEvents:UIControlEventTouchDown]; @@ -98,7 +96,7 @@ - (void)createTodayButton; - (void)createSelectedButton; { - self.selectedButton = [[UIButton alloc] initWithFrame:self.contentView.bounds]; + self.selectedButton = [[TSQCalendarRowButton alloc] initWithFrame:self.contentView.bounds]; [self.contentView addSubview:self.selectedButton]; [self configureButton:self.selectedButton]; @@ -127,11 +125,14 @@ - (void)setBeginningDate:(NSDate *)date; for (NSUInteger index = 0; index < self.daysInWeek; index++) { NSString *title = [self.dayFormatter stringFromDate:date]; + NSString *subTitle = [self.calendarView shouldDisplayEventMarkerForDate:date] ? @"•" : nil; NSString *accessibilityLabel = [self.accessibilityFormatter stringFromDate:date]; [self.dayButtons[index] setTitle:title forState:UIControlStateNormal]; [self.dayButtons[index] setAccessibilityLabel:accessibilityLabel]; + [[self.dayButtons[index] subtitleLabel] setText:subTitle]; [self.notThisMonthButtons[index] setTitle:title forState:UIControlStateNormal]; [self.notThisMonthButtons[index] setAccessibilityLabel:accessibilityLabel]; + [[self.notThisMonthButtons[index] subtitleLabel] setText:subTitle]; NSDateComponents *thisDateComponents = [self.calendar components:NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit fromDate:date]; @@ -147,9 +148,10 @@ - (void)setBeginningDate:(NSDate *)date; self.todayButton.hidden = NO; [self.todayButton setTitle:title forState:UIControlStateNormal]; [self.todayButton setAccessibilityLabel:accessibilityLabel]; + [self.todayButton.subtitleLabel setText:subTitle]; self.indexOfTodayButton = index; } else { - UIButton *button = self.dayButtons[index]; + TSQCalendarRowButton *button = self.dayButtons[index]; button.enabled = ![self.calendarView.delegate respondsToSelector:@selector(calendarView:shouldSelectDate:)] || [self.calendarView.delegate calendarView:self.calendarView shouldSelectDate:date]; button.hidden = NO; } @@ -209,8 +211,8 @@ - (void)layoutSubviews; - (void)layoutViewsForColumnAtIndex:(NSUInteger)index inRect:(CGRect)rect; { - UIButton *dayButton = self.dayButtons[index]; - UIButton *notThisMonthButton = self.notThisMonthButtons[index]; + TSQCalendarRowButton *dayButton = self.dayButtons[index]; + TSQCalendarRowButton *notThisMonthButton = self.notThisMonthButtons[index]; dayButton.frame = rect; notThisMonthButton.frame = rect; @@ -246,6 +248,7 @@ - (void)selectColumnForDate:(NSDate *)date; self.selectedButton.hidden = NO; [self.selectedButton setTitle:[self.dayButtons[newIndexOfSelectedButton] currentTitle] forState:UIControlStateNormal]; [self.selectedButton setAccessibilityLabel:[self.dayButtons[newIndexOfSelectedButton] accessibilityLabel]]; + [self.selectedButton.subtitleLabel setText:[[self.dayButtons[newIndexOfSelectedButton] subtitleLabel] text]]; } else { self.selectedButton.hidden = YES; } diff --git a/TimesSquare/TSQCalendarView.h b/TimesSquare/TSQCalendarView.h index d6f0dab..a31fbac 100644 --- a/TimesSquare/TSQCalendarView.h +++ b/TimesSquare/TSQCalendarView.h @@ -104,6 +104,15 @@ */ - (void)scrollToDate:(NSDate *)date animated:(BOOL)animated; +/** Whether a particular date should display an event marker + + This method passes straight through to the delegate + + @param date The date being displayed. + @return Whether or not the date should display an event marker. + */ +- (BOOL)shouldDisplayEventMarkerForDate:(NSDate *)date; + @end /** The methods in the `TSQCalendarViewDelegate` protocol allow the adopting delegate to either prevent a day from being selected or respond to it. @@ -131,4 +140,14 @@ */ - (void)calendarView:(TSQCalendarView *)calendarView didSelectDate:(NSDate *)date; +/** @name Displaying event markers */ + +/** Asks the delegate whether a particular date should display an event marker + + @param calendarView The calendar view that is displaying a date. + @param date The date being displayed. + @return Whether or not the date should display an event marker. + */ +- (BOOL)calendarView:(TSQCalendarView *)calendarView shouldDisplayEventMarkerForDate:(NSDate *)date; + @end diff --git a/TimesSquare/TSQCalendarView.m b/TimesSquare/TSQCalendarView.m index 5678a4e..953c052 100644 --- a/TimesSquare/TSQCalendarView.m +++ b/TimesSquare/TSQCalendarView.m @@ -162,6 +162,16 @@ - (void)scrollToDate:(NSDate *)date animated:(BOOL)animated [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section] atScrollPosition:UITableViewScrollPositionTop animated:animated]; } +- (BOOL)shouldDisplayEventMarkerForDate:(NSDate *)date +{ + if ([self.delegate respondsToSelector:@selector(calendarView:shouldDisplayEventMarkerForDate:)]) + { + return [self.delegate calendarView:self shouldDisplayEventMarkerForDate:date]; + } + + return NO; +} + - (TSQCalendarMonthHeaderCell *)makeHeaderCellWithIdentifier:(NSString *)identifier; { TSQCalendarMonthHeaderCell *cell = [[[self headerCellClass] alloc] initWithCalendar:self.calendar reuseIdentifier:identifier]; diff --git a/TimesSquareTestApp/TSQTAViewController.m b/TimesSquareTestApp/TSQTAViewController.m index 170e8bc..56e3d35 100644 --- a/TimesSquareTestApp/TSQTAViewController.m +++ b/TimesSquareTestApp/TSQTAViewController.m @@ -12,7 +12,7 @@ #import -@interface TSQTAViewController () +@interface TSQTAViewController () @property (nonatomic, retain) NSTimer *timer; @@ -39,6 +39,7 @@ - (void)loadView; calendarView.pagingEnabled = YES; CGFloat onePixel = 1.0f / [UIScreen mainScreen].scale; calendarView.contentInset = UIEdgeInsetsMake(0.0f, onePixel, 0.0f, onePixel); + calendarView.delegate = self; self.view = calendarView; } @@ -81,4 +82,12 @@ - (void)scroll; atTop = !atTop; } +- (BOOL)calendarView:(TSQCalendarView *)calendarView shouldDisplayEventMarkerForDate:(NSDate *)date +{ + NSDateComponents *components = [calendarView.calendar components:NSMonthCalendarUnit|NSDayCalendarUnit fromDate:date]; + + // This gives a nice pattern + return (components.day%9 == components.month%9) || (components.day%11 == components.month%11); +} + @end From 3005a0b83d4cfc4f4b62081a3aac3b341beed4ed Mon Sep 17 00:00:00 2001 From: Simon Booth Date: Sat, 11 May 2013 09:50:11 +0100 Subject: [PATCH 2/4] Style fixes --- TimesSquare/TSQCalendarView.m | 5 ++--- TimesSquareTestApp/TSQTAViewController.m | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/TimesSquare/TSQCalendarView.m b/TimesSquare/TSQCalendarView.m index 953c052..7667990 100644 --- a/TimesSquare/TSQCalendarView.m +++ b/TimesSquare/TSQCalendarView.m @@ -162,10 +162,9 @@ - (void)scrollToDate:(NSDate *)date animated:(BOOL)animated [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section] atScrollPosition:UITableViewScrollPositionTop animated:animated]; } -- (BOOL)shouldDisplayEventMarkerForDate:(NSDate *)date +- (BOOL)shouldDisplayEventMarkerForDate:(NSDate *)date; { - if ([self.delegate respondsToSelector:@selector(calendarView:shouldDisplayEventMarkerForDate:)]) - { + if ([self.delegate respondsToSelector:@selector(calendarView:shouldDisplayEventMarkerForDate:)]) { return [self.delegate calendarView:self shouldDisplayEventMarkerForDate:date]; } diff --git a/TimesSquareTestApp/TSQTAViewController.m b/TimesSquareTestApp/TSQTAViewController.m index 56e3d35..018a0da 100644 --- a/TimesSquareTestApp/TSQTAViewController.m +++ b/TimesSquareTestApp/TSQTAViewController.m @@ -82,12 +82,12 @@ - (void)scroll; atTop = !atTop; } -- (BOOL)calendarView:(TSQCalendarView *)calendarView shouldDisplayEventMarkerForDate:(NSDate *)date +- (BOOL)calendarView:(TSQCalendarView *)calendarView shouldDisplayEventMarkerForDate:(NSDate *)date; { NSDateComponents *components = [calendarView.calendar components:NSMonthCalendarUnit|NSDayCalendarUnit fromDate:date]; // This gives a nice pattern - return (components.day%9 == components.month%9) || (components.day%11 == components.month%11); + return (components.day % 9 == components.month % 9) || (components.day % 11 == components.month % 11); } @end From de7f636a4364d52c450a46ab456dd6d3c5f78469 Mon Sep 17 00:00:00 2001 From: Simon Booth Date: Sat, 11 May 2013 10:17:03 +0100 Subject: [PATCH 3/4] Add a rowButtonClass property. Move the button configuration into the button class. --- TimesSquare/TSQCalendarRowButton.h | 8 ++++++++ TimesSquare/TSQCalendarRowButton.m | 9 ++++++++- TimesSquare/TSQCalendarRowCell.h | 8 ++++++++ TimesSquare/TSQCalendarRowCell.m | 25 +++++++++++++------------ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/TimesSquare/TSQCalendarRowButton.h b/TimesSquare/TSQCalendarRowButton.h index d7fd88f..a15d961 100644 --- a/TimesSquare/TSQCalendarRowButton.h +++ b/TimesSquare/TSQCalendarRowButton.h @@ -9,6 +9,7 @@ #import +#import "TSQCalendarRowCell.h" /** The `TSQCalendarRowButton` class is a button that represents single day in the calendar. @@ -23,4 +24,11 @@ */ @property (nonatomic, strong, readonly) UILabel *subtitleLabel; +/** Configures the button according to the given row's properties + + The button is set up using the text color and shadow offset of the row + + */ +- (void)configureWithRowCell:(TSQCalendarRowCell *)rowCell; + @end diff --git a/TimesSquare/TSQCalendarRowButton.m b/TimesSquare/TSQCalendarRowButton.m index 4e1bcca..5ac3d5f 100644 --- a/TimesSquare/TSQCalendarRowButton.m +++ b/TimesSquare/TSQCalendarRowButton.m @@ -23,6 +23,7 @@ - (id)initWithFrame:(CGRect)frame _subtitleLabel = [[UILabel alloc] init]; _subtitleLabel.backgroundColor = [UIColor clearColor]; + _subtitleLabel.font = self.titleLabel.font; _subtitleLabel.textAlignment = UITextAlignmentCenter; [self addSubview:_subtitleLabel]; @@ -31,6 +32,13 @@ - (id)initWithFrame:(CGRect)frame return self; } +- (void)configureWithRowCell:(TSQCalendarRowCell *)rowCell +{ + [self setTitleColor:rowCell.textColor forState:UIControlStateNormal]; + self.titleLabel.shadowOffset = rowCell.shadowOffset; + [self updateSubtitleLabel]; +} + - (void)layoutSubviews { [super layoutSubviews]; @@ -43,7 +51,6 @@ - (void)layoutSubviews - (void)updateSubtitleLabel { - self.subtitleLabel.font = self.titleLabel.font; self.subtitleLabel.textColor = self.currentTitleColor; self.subtitleLabel.shadowColor = self.currentTitleShadowColor; self.subtitleLabel.shadowOffset = self.titleLabel.shadowOffset; diff --git a/TimesSquare/TSQCalendarRowCell.h b/TimesSquare/TSQCalendarRowCell.h index 0fad589..63add92 100644 --- a/TimesSquare/TSQCalendarRowCell.h +++ b/TimesSquare/TSQCalendarRowCell.h @@ -65,4 +65,12 @@ */ - (void)selectColumnForDate:(NSDate *)date; +/** @name Button configuration */ + +/** The button class to use for day buttons. + + The class should be a subclass of `TSQCalendarRowButton` or at least implement all of its methods. + */ +@property (nonatomic, strong) Class rowButtonClass; + @end diff --git a/TimesSquare/TSQCalendarRowCell.m b/TimesSquare/TSQCalendarRowCell.m index 4e3cebd..0352087 100644 --- a/TimesSquare/TSQCalendarRowCell.m +++ b/TimesSquare/TSQCalendarRowCell.m @@ -42,22 +42,23 @@ - (id)initWithCalendar:(NSCalendar *)calendar reuseIdentifier:(NSString *)reuseI return self; } -- (void)configureButton:(TSQCalendarRowButton *)button; +- (Class)rowButtonClass; { - button.titleLabel.shadowOffset = self.shadowOffset; - [button setTitleColor:self.textColor forState:UIControlStateNormal]; - button.subtitleLabel.shadowOffset = self.shadowOffset; + if (!_rowButtonClass) { + self.rowButtonClass = [TSQCalendarRowButton class]; + } + return _rowButtonClass; } - (void)createDayButtons; { NSMutableArray *dayButtons = [NSMutableArray arrayWithCapacity:self.daysInWeek]; for (NSUInteger index = 0; index < self.daysInWeek; index++) { - TSQCalendarRowButton *button = [[TSQCalendarRowButton alloc] initWithFrame:self.contentView.bounds]; + TSQCalendarRowButton *button = [[self.rowButtonClass alloc] initWithFrame:self.contentView.bounds]; [button addTarget:self action:@selector(dateButtonPressed:) forControlEvents:UIControlEventTouchDown]; [dayButtons addObject:button]; [self.contentView addSubview:button]; - [self configureButton:button]; + [button configureWithRowCell:self]; [button setTitleColor:[self.textColor colorWithAlphaComponent:0.5f] forState:UIControlStateDisabled]; } self.dayButtons = dayButtons; @@ -67,10 +68,10 @@ - (void)createNotThisMonthButtons; { NSMutableArray *notThisMonthButtons = [NSMutableArray arrayWithCapacity:self.daysInWeek]; for (NSUInteger index = 0; index < self.daysInWeek; index++) { - TSQCalendarRowButton *button = [[TSQCalendarRowButton alloc] initWithFrame:self.contentView.bounds]; + TSQCalendarRowButton *button = [[self.rowButtonClass alloc] initWithFrame:self.contentView.bounds]; [notThisMonthButtons addObject:button]; [self.contentView addSubview:button]; - [self configureButton:button]; + [button configureWithRowCell:self]; button.enabled = NO; UIColor *backgroundPattern = [UIColor colorWithPatternImage:[self notThisMonthBackgroundImage]]; @@ -82,9 +83,9 @@ - (void)createNotThisMonthButtons; - (void)createTodayButton; { - self.todayButton = [[TSQCalendarRowButton alloc] initWithFrame:self.contentView.bounds]; + self.todayButton = [[self.rowButtonClass alloc] initWithFrame:self.contentView.bounds]; [self.contentView addSubview:self.todayButton]; - [self configureButton:self.todayButton]; + [self.todayButton configureWithRowCell:self]; [self.todayButton addTarget:self action:@selector(todayButtonPressed:) forControlEvents:UIControlEventTouchDown]; [self.todayButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; @@ -96,9 +97,9 @@ - (void)createTodayButton; - (void)createSelectedButton; { - self.selectedButton = [[TSQCalendarRowButton alloc] initWithFrame:self.contentView.bounds]; + self.selectedButton = [[self.rowButtonClass alloc] initWithFrame:self.contentView.bounds]; [self.contentView addSubview:self.selectedButton]; - [self configureButton:self.selectedButton]; + [self.selectedButton configureWithRowCell:self]; [self.selectedButton setAccessibilityTraits:UIAccessibilityTraitSelected|self.selectedButton.accessibilityTraits]; From 7805e6e3ce3a2f9ed7820b92f70fd558490daeba Mon Sep 17 00:00:00 2001 From: Simon Booth Date: Sat, 11 May 2013 10:19:58 +0100 Subject: [PATCH 4/4] Style fix in button class --- TimesSquare/TSQCalendarRowButton.m | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/TimesSquare/TSQCalendarRowButton.m b/TimesSquare/TSQCalendarRowButton.m index 5ac3d5f..8c4b2ad 100644 --- a/TimesSquare/TSQCalendarRowButton.m +++ b/TimesSquare/TSQCalendarRowButton.m @@ -12,11 +12,10 @@ @implementation TSQCalendarRowButton -- (id)initWithFrame:(CGRect)frame +- (id)initWithFrame:(CGRect)frame; { self = [super initWithFrame:frame]; - if (self) - { + if (self) { self.titleLabel.font = [UIFont boldSystemFontOfSize:19.f]; self.adjustsImageWhenDisabled = NO; [self setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal]; @@ -32,14 +31,14 @@ - (id)initWithFrame:(CGRect)frame return self; } -- (void)configureWithRowCell:(TSQCalendarRowCell *)rowCell +- (void)configureWithRowCell:(TSQCalendarRowCell *)rowCell; { [self setTitleColor:rowCell.textColor forState:UIControlStateNormal]; self.titleLabel.shadowOffset = rowCell.shadowOffset; [self updateSubtitleLabel]; } -- (void)layoutSubviews +- (void)layoutSubviews; { [super layoutSubviews]; @@ -49,32 +48,32 @@ - (void)layoutSubviews self.subtitleLabel.frame = subtitleFrame; } -- (void)updateSubtitleLabel +- (void)updateSubtitleLabel; { self.subtitleLabel.textColor = self.currentTitleColor; self.subtitleLabel.shadowColor = self.currentTitleShadowColor; self.subtitleLabel.shadowOffset = self.titleLabel.shadowOffset; } -- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state +- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state; { [super setTitleShadowColor:color forState:state]; [self updateSubtitleLabel]; } -- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state +- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state; { [super setTitleColor:color forState:state]; [self updateSubtitleLabel]; } -- (void)setHighlighted:(BOOL)highlighted +- (void)setHighlighted:(BOOL)highlighted; { [super setHighlighted:highlighted]; [self updateSubtitleLabel]; } -- (void)setSelected:(BOOL)selected +- (void)setSelected:(BOOL)selected; { [super setSelected:selected]; [self updateSubtitleLabel];