From ca7495e2246130676651bf0e9d3a8806ca99d1ca Mon Sep 17 00:00:00 2001 From: Charles Marsh Date: Sat, 3 Nov 2012 15:09:16 +0000 Subject: [PATCH] added ability to put multiple markers on date --- demo/iPhone/DemoCalendarMonth.m | 10 ++--- src/TapkuLibrary/TKCalendarMonthView.h | 4 +- src/TapkuLibrary/TKCalendarMonthView.m | 57 ++++++++++++++++++++------ 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/demo/iPhone/DemoCalendarMonth.m b/demo/iPhone/DemoCalendarMonth.m index 3786741d..4a360d80 100755 --- a/demo/iPhone/DemoCalendarMonth.m +++ b/demo/iPhone/DemoCalendarMonth.m @@ -116,15 +116,15 @@ - (void) generateRandomDataForStartDate:(NSDate*)start endDate:(NSDate*)end{ int r = arc4random(); if(r % 3==1){ - [self.dataDictionary setObject:[NSArray arrayWithObjects:@"Item one",@"Item two",nil] forKey:d]; - [self.dataArray addObject:[NSNumber numberWithBool:YES]]; + [self.dataDictionary setObject:[NSArray arrayWithObjects:@"Item one",@"Item two",@"Item three",@"Item four",nil] forKey:d]; + [self.dataArray addObject:[NSNumber numberWithInt:4]]; }else if(r%4==1){ - [self.dataDictionary setObject:[NSArray arrayWithObjects:@"Item one",nil] forKey:d]; - [self.dataArray addObject:[NSNumber numberWithBool:YES]]; + [self.dataDictionary setObject:[NSArray arrayWithObjects:@"Item one",@"Item two",@"Item three",@"Item four",@"Item five",nil] forKey:d]; + [self.dataArray addObject:[NSNumber numberWithInt:5]]; }else - [self.dataArray addObject:[NSNumber numberWithBool:NO]]; + [self.dataArray addObject:[NSNumber numberWithInt:0]]; TKDateInformation info = [d dateInformationWithTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; diff --git a/src/TapkuLibrary/TKCalendarMonthView.h b/src/TapkuLibrary/TKCalendarMonthView.h index bcb2ee0d..d2ae5034 100644 --- a/src/TapkuLibrary/TKCalendarMonthView.h +++ b/src/TapkuLibrary/TKCalendarMonthView.h @@ -124,8 +124,8 @@ @param monthView The calendar month grid. @param startDate The first date shown by the calendar month grid. @param lastDate The last date shown by the calendar month grid. - @return Returns an array of NSNumber objects corresponding the number of days specified in the start and last day parameters. Each NSNumber variable will give a BOOL value that will be used to display a dot under the day. - + @return Returns an array of NSNumber objects corresponding the number of days specified in the start and last day parameters. Each NSNumber variable will give a INTEGER value i that will be used to display i dots under the day. + If i exceeds 4, the dot is instead drawn as a * (star). */ - (NSArray*) calendarMonthView:(TKCalendarMonthView*)monthView marksFromDate:(NSDate*)startDate toDate:(NSDate*)lastDate; @end \ No newline at end of file diff --git a/src/TapkuLibrary/TKCalendarMonthView.m b/src/TapkuLibrary/TKCalendarMonthView.m index f516f6ae..216c5185 100644 --- a/src/TapkuLibrary/TKCalendarMonthView.m +++ b/src/TapkuLibrary/TKCalendarMonthView.m @@ -259,6 +259,9 @@ - (id) initWithMonth:(NSDate*)date marks:(NSArray*)markArray startDayOnSunday:(B [self.selectedImageView addSubview:self.currentDay]; [self.selectedImageView addSubview:self.dot]; + if (self.dateSelected) { + self.dot.text = [self stringWithMarks:[[markArray objectAtIndex:[[dates objectAtIndex:0] daysBetweenDate:self.dateSelected]] integerValue]]; + } self.multipleTouchEnabled = NO; @@ -269,6 +272,12 @@ - (void) setTarget:(id)t action:(SEL)a{ action = a; } + +- (NSString*)stringWithMarks:(int)marksForDay +{ + return (marksForDay < 5)? [@"••••" substringToIndex:marksForDay] : @"*"; + +} - (CGRect) rectForCellAtIndex:(int)index{ @@ -277,7 +286,7 @@ - (CGRect) rectForCellAtIndex:(int)index{ return CGRectMake(col*46, row*44+6, 47, 45); } -- (void) drawTileInRect:(CGRect)r day:(int)day mark:(BOOL)mark font:(UIFont*)f1 font2:(UIFont*)f2{ +- (void) drawTileInRect:(CGRect)r day:(int)day mark:(int)mark font:(UIFont*)f1 font2:(UIFont*)f2{ NSString *str = [NSString stringWithFormat:@"%d",day]; @@ -289,10 +298,12 @@ - (void) drawTileInRect:(CGRect)r day:(int)day mark:(BOOL)mark font:(UIFont*)f1 alignment: UITextAlignmentCenter]; if(mark){ + NSString *markString = [self stringWithMarks:mark]; + r.size.height = 10; - r.origin.y += 18; - - [@"•" drawInRect: r + r.origin.y += ([markString isEqualToString:@"*"])? 22 : 18; + + [markString drawInRect: r withFont: f2 lineBreakMode: UILineBreakModeWordWrap alignment: UITextAlignmentCenter]; @@ -327,9 +338,9 @@ - (void) drawRect:(CGRect)rect { for(int i = firstOfPrev;i<= lastOfPrev;i++){ r = [self rectForCellAtIndex:index]; if ([marks count] > 0) - [self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] boolValue] font:font font2:font2]; + [self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] integerValue] font:font font2:font2]; else - [self drawTileInRect:r day:i mark:NO font:font font2:font2]; + [self drawTileInRect:r day:i mark:0 font:font font2:font2]; index++; } } @@ -343,9 +354,9 @@ - (void) drawRect:(CGRect)rect { if(today == i) [[UIColor whiteColor] set]; if ([marks count] > 0) - [self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] boolValue] font:font font2:font2]; + [self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] integerValue] font:font font2:font2]; else - [self drawTileInRect:r day:i mark:NO font:font font2:font2]; + [self drawTileInRect:r day:i mark:0 font:font font2:font2]; if(today == i) [color set]; index++; } @@ -355,9 +366,9 @@ - (void) drawRect:(CGRect)rect { while(index % 7 != 0){ r = [self rectForCellAtIndex:index] ; if ([marks count] > 0) - [self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] boolValue] font:font font2:font2]; + [self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] integerValue] font:font font2:font2]; else - [self drawTileInRect:r day:i mark:NO font:font font2:font2]; + [self drawTileInRect:r day:i mark:0 font:font font2:font2]; i++; index++; } @@ -366,7 +377,7 @@ - (void) drawRect:(CGRect)rect { } - (void) selectDay:(int)day{ - + int pre = firstOfPrev < 0 ? 0 : lastOfPrev - firstOfPrev + 1; int tot = day + pre; @@ -401,6 +412,16 @@ - (void) selectDay:(int)day{ if ([marks count] > 0) { if([[marks objectAtIndex: row * 7 + column ] boolValue]){ + self.dot.text = [self stringWithMarks:[[marks objectAtIndex:(row*7+column)] integerValue]]; + if ([self.dot.text isEqualToString:@"*"]) { + CGRect r = self.selectedImageView.bounds; + r.origin.y += 17; + self.dot.frame = r; + } else { + CGRect r = self.selectedImageView.bounds; + r.origin.y += 13; + self.dot.frame = r; + } [self.selectedImageView addSubview:self.dot]; }else{ [self.dot removeFromSuperview]; @@ -495,9 +516,19 @@ - (void) reactToTouch:(UITouch*)touch down:(BOOL)down{ self.currentDay.text = [NSString stringWithFormat:@"%d",day]; if ([marks count] > 0) { - if([[marks objectAtIndex: row * 7 + column] boolValue]) + if([[marks objectAtIndex: row * 7 + column] boolValue]) { + self.dot.text = [self stringWithMarks:[[marks objectAtIndex:(row*7+column)] integerValue]]; + if ([self.dot.text isEqualToString:@"*"]) { + CGRect r = self.selectedImageView.bounds; + r.origin.y += 17; + self.dot.frame = r; + } else { + CGRect r = self.selectedImageView.bounds; + r.origin.y += 13; + self.dot.frame = r; + } [self.selectedImageView addSubview:self.dot]; - else + } else [self.dot removeFromSuperview]; }else{ [self.dot removeFromSuperview];