Permalink
Browse files

Fix for calendar grid height issue.

  • Loading branch information...
1 parent d74d48b commit dbb3b9c502069f1672899845f85721e1e816cb21 @devinross committed Apr 24, 2012
@@ -36,14 +36,11 @@ @implementation DemoCalendarMonth
@synthesize dataArray, dataDictionary;
-
-
- (void) viewDidLoad{
[super viewDidLoad];
[self.monthView selectDate:[NSDate month]];
}
-
- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
@@ -78,16 +75,16 @@ - (void) calendarMonthView:(TKCalendarMonthView*)mv monthDidChange:(NSDate*)d an
}
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *ar = [dataDictionary objectForKey:[self.monthView dateSelected]];
if(ar == nil) return 0;
return [ar count];
}
-- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+- (UITableViewCell *) tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
@@ -140,7 +140,7 @@ - (void) tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)inde
}
if(s==0&&r==1)
- vc = [[DemoCalendarMonth alloc] initWithSunday:NO];
+ vc = [[DemoCalendarMonth alloc] initWithSunday:YES];
@@ -156,13 +156,7 @@ - (void) tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)inde
vc = [[MapViewController alloc] init];
- /*
- else if(s==2 && r==0)
- vc = [[DemoCalendarMonth alloc] initWithSunday:YES];
- else if(s==2 && r==1)
- vc = [[TKCalendarDayViewController alloc] init];
- */
-
+
else if(s==2 && r==0)
vc = [[LabelViewController alloc] initWithStyle:UITableViewStyleGrouped];
else if(s==2 && r==1)
@@ -47,12 +47,12 @@ - (void) loadView{
float y,height;
y = self.monthView.frame.origin.y + self.monthView.frame.size.height;
height = self.view.frame.size.height - y;
-
+
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, y, self.view.bounds.size.width, height) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
- _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
+ _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_tableView];
[self.view sendSubviewToBack:_tableView];
}
@@ -93,9 +93,6 @@ - (NSDate*) previousMonth{
}
-
-
-
- (NSDate*) lastOfMonthDate {
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comp = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit) fromDate:self];
@@ -122,13 +119,10 @@ + (NSDate*) lastOfCurrentMonth{
return [gregorian dateFromComponents:comp];
}
-
-
@end
#pragma mark -
-
@interface TKCalendarMonthTiles : UIView {
id target;
@@ -160,19 +154,15 @@ + (NSArray*) rangeOfDatesInMonthGrid:(NSDate*)date startOnSunday:(BOOL)sunday;
@end
#pragma mark -
-
#define dotFontSize 18.0
#define dateFontSize 22.0
-
@interface TKCalendarMonthTiles (private)
-
@property (strong,nonatomic) UIImageView *selectedImageView;
@property (strong,nonatomic) UILabel *currentDay;
@property (strong,nonatomic) UILabel *dot;
@end
#pragma mark -
-
@implementation TKCalendarMonthTiles
@synthesize monthDate;
@@ -267,24 +257,28 @@ - (id) initWithMonth:(NSDate*)date marks:(NSArray*)markArray startDayOnSunday:(B
monthDate = date;
startOnSunday = sunday;
-
-
TKDateInformation dateInfo = [monthDate dateInformationWithTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
firstWeekday = dateInfo.weekday;
- NSDate *prev = [monthDate previousMonth];
- //NSDate *next = [monthDate nextMonth];
-
+ NSDate *prev = [monthDate previousMonth];
daysInMonth = [[monthDate nextMonth] daysBetweenDate:monthDate];
+ /*
int row = (daysInMonth + dateInfo.weekday - 1);
if(dateInfo.weekday==1&&!sunday) row = daysInMonth + 6;
if(!sunday) row--;
row = (row / 7) + ((row % 7 == 0) ? 0:1);
float h = 44 * row;
+ */
+
+ NSArray *dates = [TKCalendarMonthTiles rangeOfDatesInMonthGrid:date startOnSunday:sunday];
+ NSUInteger numberOfDaysBetween = [[dates objectAtIndex:0] daysBetweenDate:[dates lastObject]];
+ NSUInteger scale = (numberOfDaysBetween / 7) + 1;
+ CGFloat h = 44.0f * scale;
+
TKDateInformation todayInfo = [[NSDate date] dateInformation];
today = dateInfo.month == todayInfo.month && dateInfo.year == todayInfo.year ? todayInfo.day : -5;
@@ -301,13 +295,10 @@ - (id) initWithMonth:(NSDate*)date marks:(NSArray*)markArray startDayOnSunday:(B
firstOfPrev = preDayCnt - firstWeekday+3;
}
lastOfPrev = preDayCnt;
-
}
-
-
- self.frame = CGRectMake(0, 1, 320, h+1);
+ self.frame = CGRectMake(0, 1.0, 320.0f, h+1);
[self.selectedImageView addSubview:self.currentDay];
[self.selectedImageView addSubview:self.dot];
@@ -490,7 +481,6 @@ - (NSDate*) dateSelected{
}
-
- (void) reactToTouch:(UITouch*)touch down:(BOOL)down{
CGPoint p = [touch locationInView:self];
@@ -624,17 +614,16 @@ - (UIImageView *) selectedImageView{
@end
-#pragma mark -
-@interface TKCalendarMonthView (private)
+#pragma mark -
+@interface TKCalendarMonthView (private)
@property (strong,nonatomic) UIScrollView *tileBox;
@property (strong,nonatomic) UIImageView *topBackground;
@property (strong,nonatomic) UILabel *monthYear;
@property (strong,nonatomic) UIButton *leftArrow;
@property (strong,nonatomic) UIButton *rightArrow;
@property (strong,nonatomic) UIImageView *shadow;
-
@end
#pragma mark -
@@ -651,19 +640,12 @@ - (id) initWithSundayAsFirst:(BOOL)s{
self.backgroundColor = [UIColor grayColor];
sunday = s;
-
-
-
currentTile = [[TKCalendarMonthTiles alloc] initWithMonth:[[NSDate date] firstOfMonth] marks:nil startDayOnSunday:sunday];
[currentTile setTarget:self action:@selector(tile:)];
CGRect r = CGRectMake(0, 0, self.tileBox.bounds.size.width, self.tileBox.bounds.size.height + self.tileBox.frame.origin.y);
-
-
self.frame = r;
-
-
[self addSubview:self.topBackground];
[self.tileBox addSubview:currentTile];
[self addSubview:self.tileBox];
@@ -715,16 +697,12 @@ - (id) initWithSundayAsFirst:(BOOL)s{
sund.day = 11;
NSString *sat = [dateFormat stringFromDate:[NSDate dateFromDateInformation:sund timeZone:tz]];
-
-
-
NSArray *ar;
if(sunday) ar = [NSArray arrayWithObjects:sun,mon,tue,wed,thu,fri,sat,nil];
else ar = [NSArray arrayWithObjects:mon,tue,wed,thu,fri,sat,sun,nil];
int i = 0;
for(NSString *s in ar){
-
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(46 * i, 29, 46, 15)];
[self addSubview:label];
label.text = s;
@@ -734,7 +712,6 @@ - (id) initWithSundayAsFirst:(BOOL)s{
label.font = [UIFont systemFontOfSize:11];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithRed:59/255. green:73/255. blue:88/255. alpha:1];
-
i++;
}
@@ -867,7 +844,6 @@ - (NSDate*) monthDate{
return [currentTile monthDate];
}
- (void) selectDate:(NSDate*)date{
- //TKDateInformation info = [date dateInformation];
TKDateInformation info = [date dateInformationWithTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSDate *month = [date firstOfMonth];
@@ -986,12 +962,7 @@ - (UIButton *) leftArrow{
leftArrow = [UIButton buttonWithType:UIButtonTypeCustom];
leftArrow.tag = 0;
[leftArrow addTarget:self action:@selector(changeMonth:) forControlEvents:UIControlEventTouchUpInside];
-
-
-
-
[leftArrow setImage:[UIImage imageNamedTK:@"TapkuLibrary.bundle/Images/calendar/Month Calendar Left Arrow"] forState:0];
-
leftArrow.frame = CGRectMake(0, 0, 48, 38);
}
return leftArrow;
@@ -1002,11 +973,7 @@ - (UIButton *) rightArrow{
rightArrow.tag = 1;
[rightArrow addTarget:self action:@selector(changeMonth:) forControlEvents:UIControlEventTouchUpInside];
rightArrow.frame = CGRectMake(320-45, 0, 48, 38);
-
-
-
[rightArrow setImage:[UIImage imageNamedTK:@"TapkuLibrary.bundle/Images/calendar/Month Calendar Right Arrow"] forState:0];
-
}
return rightArrow;
}
@@ -37,9 +37,7 @@
/** The `TKCalendarMonthViewController` class creates a controller object that manages a calendar month grid. */
-@interface TKCalendarMonthViewController : UIViewController <TKCalendarMonthViewDelegate,TKCalendarMonthViewDataSource> {
- BOOL _sundayFirst;
-}
+@interface TKCalendarMonthViewController : UIViewController <TKCalendarMonthViewDelegate,TKCalendarMonthViewDataSource>
/** Initializes a month view controller to manage a month grid. Sunday will be the left-most day.
@return A newly create month view controller.
@@ -32,6 +32,12 @@
#import "TKCalendarMonthView.h"
+@interface TKCalendarMonthViewController () {
+ BOOL _sundayFirst;
+}
+
+@end
+
@implementation TKCalendarMonthViewController
@synthesize monthView = _monthView;

0 comments on commit dbb3b9c

Please sign in to comment.