forked from vfr/Reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMDAudioPlayerTableViewCell.m
More file actions
153 lines (115 loc) · 3.22 KB
/
MDAudioPlayerTableViewCell.m
File metadata and controls
153 lines (115 loc) · 3.22 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// MDAudioPlayerTableViewCell.m
// MDAudioPlayerSample
//
// Created by Matt Donnelly on 04/08/2010.
// Copyright 2010 Matt Donnelly. All rights reserved.
//
#import "MDAudioPlayerTableViewCell.h"
@interface MDTableViewCellView : UIView
@end
@implementation MDTableViewCellView
- (void)drawRect:(CGRect)r
{
[(MDAudioPlayerTableViewCell *)[self superview] drawContentView:r];
}
@end
@implementation MDAudioPlayerTableViewCell
@synthesize title;
@synthesize number;
@synthesize duration;
@synthesize isEven;
@synthesize isSelectedIndex;
static UIFont *textFont = nil;
+ (void)initialize
{
if (self == [MDAudioPlayerTableViewCell class])
{
textFont = [[UIFont boldSystemFontOfSize:15] retain];
}
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
{
contentView = [[MDTableViewCellView alloc] initWithFrame:CGRectZero];
contentView.opaque = NO;
[self addSubview:contentView];
[contentView release];
}
return self;
}
- (void)dealloc
{
[title release];
[number release];
[duration release];
[super dealloc];
}
- (void)setTitle:(NSString *)s
{
[title release];
title = [s copy];
[self setNeedsDisplay];
}
- (void)setNumber:(NSString *)s
{
[number release];
number = [s copy];
[self setNeedsDisplay];
}
- (void)setDuration:(NSString *)s
{
[duration release];
duration = [s copy];
[self setNeedsDisplay];
}
- (void)setIsSelectedIndex:(BOOL)flag
{
isSelectedIndex = flag;
[self setNeedsDisplay];
}
- (void)setFrame:(CGRect)f
{
[super setFrame:f];
[contentView setFrame:[self bounds]];
}
- (void)setNeedsDisplay
{
[super setNeedsDisplay];
[contentView setNeedsDisplay];
}
- (void)drawContentView:(CGRect)r
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *bgColor;
if (self.highlighted)
bgColor = [UIColor clearColor];
else
bgColor = self.isEven ? [UIColor colorWithWhite:0.0 alpha:0.25] : [UIColor clearColor];
UIColor *textColor = [UIColor whiteColor];
UIColor *dividerColor = self.highlighted ? [UIColor clearColor] : [UIColor colorWithRed:0.986 green:0.933 blue:0.994 alpha:0.13];
[bgColor set];
CGContextFillRect(context, r);
[textColor set];
[title drawInRect:CGRectMake(75, 12, 185, 15) withFont:textFont lineBreakMode:UILineBreakModeTailTruncation];
[number drawInRect:CGRectMake(5, 12, 35, 15) withFont:textFont lineBreakMode:UILineBreakModeTailTruncation];
[duration drawInRect:CGRectMake(270, 12, 45, 15) withFont:textFont lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentRight];
[dividerColor set];
CGContextSetLineWidth(context, 0.5);
CGContextMoveToPoint(context, 63.5, 0.0);
CGContextAddLineToPoint(context, 63.5, r.size.height);
CGContextMoveToPoint(context, 260.5, 0.0);
CGContextAddLineToPoint(context, 260.5, r.size.height);
CGContextStrokePath(context);
if (self.isSelectedIndex)
{
[self.highlighted ? [UIColor whiteColor] : [UIColor colorWithRed:0.090 green:0.274 blue:0.873 alpha:1.000] set];
CGContextMoveToPoint(context, 45, 17);
CGContextAddLineToPoint(context, 45, 27);
CGContextAddLineToPoint(context, 55, 22);
CGContextClosePath(context);
CGContextFillPath(context);
}
}
@end