Skip to content

Commit

Permalink
Calendar Day View minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinross committed Jun 3, 2014
1 parent c217351 commit 3f69bc2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
25 changes: 15 additions & 10 deletions src/TapkuLibrary/TKCalendarDayEventView.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,34 +104,39 @@ - (void) _setupView{
- (void) layoutSubviews{
[super layoutSubviews];

CGFloat h = CGRectGetHeight(self.frame);
if(h < 45){
CGFloat blockHeight = CGRectGetHeight(self.frame);
if(blockHeight < 45){
self.titleLabel.frame = CGRectInset(self.bounds, 5, 5);
CGFloat y = CGRectGetMaxY(self.titleLabel.frame);
self.locationLabel.frame = CGRectMake(CGRectGetMinX(self.titleLabel.frame), y, 0, 0);
self.locationLabel.hidden = YES;
return;
}


CGFloat hh = h > 200 ? 14 * 2 : 14;

CGFloat hh = blockHeight > 200 ? 14 * 2 : 14;
CGRect r = CGRectInset(self.bounds, 5, 5);
r.size.height = hh;
r = CGRectIntersection(r, self.bounds);

self.titleLabel.frame = r;
[self.titleLabel sizeToFit];

hh = h > 200 ? (FONT_SIZE+2.0) * 2 : FONT_SIZE+2;


hh = blockHeight > 200 ? (FONT_SIZE+2.0) * 2 : FONT_SIZE+2;
r = CGRectInset(self.bounds, 5, 5);
r.size.height = hh;
r.origin.y += CGRectGetHeight(self.titleLabel.frame);
r = CGRectIntersection(r, self.bounds);

r.origin.y = CGRectGetMaxY(self.titleLabel.frame);
CGFloat maxLocationHeight = CGRectGetHeight(self.frame) - CGRectGetMinY(r);
r.size.height = MIN(maxLocationHeight, r.size.height);


self.locationLabel.frame = r;
self.locationLabel.hidden = self.locationLabel.text.length > 0 ? NO : YES;
[self.locationLabel sizeToFit];

CGSize s = [self.locationLabel sizeThatFits:r.size];
r.size.height = MIN(maxLocationHeight,s.height);
self.locationLabel.frame = r;
}

- (CGFloat) contentHeight{
Expand Down
34 changes: 31 additions & 3 deletions src/TapkuLibrary/TKCalendarDayView.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ @interface TKTimelineView : UIView
@property (nonatomic,strong) NSArray *times;
@property (nonatomic,strong) UIColor *hourColor;
@property (nonatomic,assign) BOOL is24hClock;
@property (nonatomic,assign) BOOL isToday;
@end

@interface TKWeekdaysView : UIView
Expand Down Expand Up @@ -441,6 +442,7 @@ - (void) _reloadData{
[self _setupDaysView];
[self _scrollToTopEvent:NO];
[self.nowLineView updateTime];

}
- (void) _refreshDataWithPageAtIndex:(NSInteger)index{

Expand All @@ -463,6 +465,8 @@ - (void) _refreshDataWithPageAtIndex:(NSInteger)index{
}
}

timeline.isToday = NO;

if(self.nowLineView.superview == sv) [self.nowLineView removeFromSuperview];
if([timeline.date isTodayWithTimeZone:self.calendar.timeZone]){

Expand All @@ -479,10 +483,12 @@ - (void) _refreshDataWithPageAtIndex:(NSInteger)index{
CGRect eventFrame = CGRectMake(CGRectGetMinX(self.nowLineView.frame), hourStartPosition + minuteStartPosition - 5, CGRectGetWidth(self.frame), 14);
self.nowLineView.frame = eventFrame;
[sv addSubview:self.nowLineView];
timeline.isToday = YES;

}


[timeline setNeedsDisplay];

if(!self.dataSource) return;
timeline.events = [NSMutableArray arrayWithArray:[self.dataSource calendarDayTimelineView:self eventsForDate:timeline.date]];

Expand Down Expand Up @@ -1062,14 +1068,35 @@ - (void) drawRect:(CGRect)rect {
UIFont *timeFont = [UIFont systemFontOfSize:FONT_SIZE];
UIColor *timeColor = [UIColor blackColor];
UIColor *lineColor = [UIColor colorWithHex:0xd7d7d7];

NSInteger discount = - 100;

if(self.isToday){

NSDate *now = [NSDate date];
NSDateFormatter *form = [[NSDateFormatter alloc] init];
form.dateFormat = @"H";
NSInteger hour = [[form stringFromDate:now] integerValue];
form.dateFormat = @"m";

NSInteger minute = [[form stringFromDate:now] integerValue];

if(minute > 39)
discount = hour+1;
else if(minute < 21)
discount = hour;

}

// Draw each times string
for (NSInteger i=0; i<self.times.count; i++) {

[timeColor set];
CGRect timeRect = CGRectMake(2.0, i * VERTICAL_DIFF + VERTICAL_INSET - 7, LEFT_INSET - 2.0f - 6, FONT_SIZE + 2.0);

[self.times[i] drawInRect:timeRect withFont:timeFont lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentRight];

if(i != discount)
[self.times[i] drawInRect:timeRect withFont:timeFont lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentRight];

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
Expand Down Expand Up @@ -1185,7 +1212,8 @@ - (id) init{
if(!(self=[super initWithFrame:CGRectMake(0, 0, 320, 14)])) return nil;

self.autoresizingMask = UIViewAutoresizingFlexibleWidth;

self.userInteractionEnabled = NO;

self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 0, LEFT_INSET-2, CGRectGetHeight(self.frame))];
self.timeLabel.textColor = self.tintColor;
self.timeLabel.font = [UIFont boldSystemFontOfSize:10];
Expand Down

0 comments on commit 3f69bc2

Please sign in to comment.