-
Notifications
You must be signed in to change notification settings - Fork 6
/
YTQueueTableCell.m
100 lines (85 loc) · 3.21 KB
/
YTQueueTableCell.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// YTQueueTableCell.m
// YourTurn
//
// Created by Masashi Ono on 09/06/20.
// Copyright (c) 2009, Masashi Ono
// All rights reserved.
//
#import "YTQueueTableCell.h"
#import "YTAttendee.h"
#import "NSString+YourTurn.h"
@implementation YTQueueTableCell
#pragma mark properties
- (CGFloat)height
{
return 72.0;
}
# pragma mark init, dealloc, memory management
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier])
{
nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
nameLabel.font = [UIFont boldSystemFontOfSize:26.0];
nameLabel.backgroundColor = [UIColor clearColor];
nameLabel.opaque = NO;
indexLabel = [[UILabel alloc] initWithFrame:CGRectZero];
indexLabel.font = [UIFont systemFontOfSize:16.0];
indexLabel.textColor = [UIColor colorWithHue:0.33 saturation:1.0 brightness:0.5 alpha:1.0];
indexLabel.backgroundColor = [UIColor clearColor];
indexLabel.opaque = NO;
timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
timeLabel.font = [UIFont fontWithName:@"Courier New" size:16.0];
timeLabel.textAlignment = UITextAlignmentRight;
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.opaque = NO;
[self.contentView addSubview:nameLabel];
[self.contentView addSubview:indexLabel];
[self.contentView addSubview:timeLabel];
self.selectionStyle = UITableViewCellSelectionStyleBlue;
}
return self;
}
- (void)dealloc
{
// Do not release attendee since it's not retained
[nameLabel release];
[indexLabel release];
[timeLabel release];
[super dealloc];
}
#pragma mark UITableViewCell method
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect bounds = self.contentView.bounds;
indexLabel.frame = CGRectMake(10.0, 2.0, 40.0, 20.0);
nameLabel.frame = CGRectMake(40.0, 0, bounds.size.width, 72.0 - 1.0); // Leave a space for sparator
timeLabel.frame = CGRectMake(bounds.size.width - 200.0, 50.0, 180.0, 22.0 - 1.0); // Leave a space for sparator
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGGradientRef gradient;
CGColorSpaceRef colorSpace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { 1.0, 1.0, 1.0, 1.0, // Start color
0.79, 0.79, 0.79, 1.0 }; // End color
colorSpace = CGColorSpaceCreateDeviceRGB();
gradient = CGGradientCreateWithColorComponents(colorSpace, components,
locations, num_locations);
CGPoint startPoint = CGPointMake(self.frame.size.width/2, 0.0);
CGPoint endPoint = CGPointMake(self.frame.size.width/2, self.frame.size.height);
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
}
#pragma mark other method
- (void)setLabelsWithIndex:(NSUInteger)index andAttendee:(YTAttendee *)attendee
{
nameLabel.text = attendee.name;
indexLabel.text = [NSString stringWithFormat:@"# %d", index];
timeLabel.text = [NSString stringHMSFormatWithAllottedTime:attendee.allottedTime];
[self setNeedsDisplay];
}
@end