-
Notifications
You must be signed in to change notification settings - Fork 1
/
TLTableViewCell.m
105 lines (84 loc) · 2.83 KB
/
TLTableViewCell.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
101
102
103
104
105
//
// TLTableViewCell.m
// TLCommon
//
// Created by Joshua Bleecher Snyder on 10/7/09.
//
#import "TLTableViewCell.h"
#pragma mark -
@interface TLTableViewCell ()
@end
#pragma mark -
@implementation TLTableViewCell
@synthesize cellColor;
@synthesize selectedCellColor;
+ (TLTableViewCell *)tableViewCellWithStyle:(UITableViewCellStyle)style
dequeuedIfPossibleFromTableView:(UITableView *)tableView {
return [self tableViewCellWithStyle:style
dequeuedIfPossibleFromTableView:tableView
reuseIdentifier:[self defaultReuseIdentifier]];
}
+ (TLTableViewCell *)tableViewCellWithStyle:(UITableViewCellStyle)style
dequeuedIfPossibleFromTableView:(UITableView *)tableView
reuseIdentifier:(NSString *)reuseIdentifier {
TLTableViewCell *cell = (TLTableViewCell *)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if(!cell) {
cell = [[[self alloc] initWithStyle:style reuseIdentifier:reuseIdentifier] autorelease];
}
return cell;
}
+ (NSString *)defaultReuseIdentifier {
return NSStringFromClass(self);
}
- (void)setSelected:(BOOL)selected
animated:(BOOL)animated {
[super setSelected:selected animated:animated];
UIColor *color = selected ? self.selectedCellColor : self.cellColor;
if(!selected) {
// this is a bit of a hack -- well, more than a bit
// but w/o it the accessory area of the cell looks hideous
// b/c it fades slowly but the rest of the cell immediately
// snaps back to a non-selected appearance. i wish i knew
// how to fix this. advice, dear github wanderer?
self.selectedBackgroundView = nil;
}
if(color) {
self.textLabel.backgroundColor = color;
self.detailTextLabel.backgroundColor = color;
self.contentView.backgroundColor = color;
}
}
- (void)dealloc {
[cellColor release], cellColor = nil;
[selectedCellColor release], selectedCellColor = nil;
[super dealloc];
}
#pragma mark -
#pragma mark Overridden accessors
- (void)setCellColor:(UIColor *)newCellColor {
if(!self.backgroundView) {
self.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}
if(!newCellColor) {
self.backgroundView = nil;
}
[newCellColor retain];
[cellColor release];
cellColor = newCellColor;
self.backgroundView.backgroundColor = cellColor;
[self setNeedsDisplay];
}
- (void)setSelectedCellColor:(UIColor *)newSelectedCellColor {
if(!self.selectedBackgroundView) {
self.selectedBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}
if(!newSelectedCellColor) {
self.selectedBackgroundView = nil;
}
[newSelectedCellColor retain];
[selectedCellColor release];
selectedCellColor = newSelectedCellColor;
self.selectedBackgroundView.backgroundColor = selectedCellColor;
[self setNeedsDisplay];
}
@end