|
9 | 9 | #import "CustomCell.h"
|
10 | 10 |
|
11 | 11 |
|
| 12 | +//==================================================================== |
| 13 | + |
| 14 | +@interface SlideView : UIView { |
| 15 | +} |
| 16 | +@end |
| 17 | + |
| 18 | +@implementation SlideView |
| 19 | + |
| 20 | + |
| 21 | +#define CUSTOMCELL_OBJECT_LENGTH 10.0 |
| 22 | +#define CUSTOMCELL_SHADOW_OFFSET 5.0 |
| 23 | +#define CUSTOMCELL_SHADOW_BLUR 5.0 |
| 24 | + |
| 25 | +- (void)drawRect:(CGRect)rect |
| 26 | +{ |
| 27 | + // draw edge shadow |
| 28 | + // NSLog(@"-[SlideView drawRect:] %@", NSStringFromCGRect(rect)); |
| 29 | + CGRect frame = self.bounds; |
| 30 | + frame.origin.x -= CUSTOMCELL_OBJECT_LENGTH; |
| 31 | + frame.origin.y -= CUSTOMCELL_OBJECT_LENGTH; |
| 32 | + frame.size.width += CUSTOMCELL_OBJECT_LENGTH; |
| 33 | + frame.size.height = CUSTOMCELL_OBJECT_LENGTH; |
| 34 | + |
| 35 | + CGContextRef context = UIGraphicsGetCurrentContext(); |
| 36 | + |
| 37 | + CGContextSetShadow(context,CGSizeMake(CUSTOMCELL_SHADOW_OFFSET, CUSTOMCELL_SHADOW_OFFSET), CUSTOMCELL_SHADOW_BLUR); |
| 38 | + |
| 39 | + [[UIColor whiteColor] setFill]; |
| 40 | + CGContextFillRect(context, frame); |
| 41 | + |
| 42 | +} |
| 43 | + |
| 44 | +@end; |
| 45 | + |
| 46 | +//==================================================================== |
| 47 | + |
| 48 | + |
| 49 | +@interface BaseView : UIView { |
| 50 | +} |
| 51 | +@property (nonatomic, assign) BOOL selected; |
| 52 | +@end |
| 53 | + |
| 54 | + |
| 55 | +@implementation BaseView |
| 56 | +@synthesize selected; |
| 57 | + |
| 58 | +- (void)drawRect:(CGRect)rect |
| 59 | +{ |
| 60 | + // draw |
| 61 | + // NSLog(@"-[BaseView drawRect:] %@", NSStringFromCGRect(rect)); |
| 62 | + |
| 63 | + if (selected) { |
| 64 | + |
| 65 | + CGContextRef context = UIGraphicsGetCurrentContext(); |
| 66 | + |
| 67 | + CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); |
| 68 | + CGFloat components[] = { 0.9f, 0.9f, 0.9f, 0.9f, |
| 69 | + 0.7f, 0.7f, 0.7f, 0.7f }; |
| 70 | + |
| 71 | + |
| 72 | + size_t count = sizeof(components)/ (sizeof(CGFloat)* 4); |
| 73 | + |
| 74 | + |
| 75 | + CGContextAddRect(context, self.frame); |
| 76 | + |
| 77 | + CGRect frame = self.bounds; |
| 78 | + CGPoint startPoint = frame.origin; |
| 79 | + CGPoint endPoint = frame.origin; |
| 80 | + endPoint.y = frame.origin.y + frame.size.height; |
| 81 | + |
| 82 | + CGGradientRef gradientRef = |
| 83 | + CGGradientCreateWithColorComponents(colorSpaceRef, components, NULL, count); |
| 84 | + |
| 85 | + CGContextDrawLinearGradient(context, |
| 86 | + gradientRef, |
| 87 | + startPoint, |
| 88 | + endPoint, |
| 89 | + kCGGradientDrawsAfterEndLocation); |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + CGGradientRelease(gradientRef); |
| 94 | + CGColorSpaceRelease(colorSpaceRef); |
| 95 | + } |
| 96 | +} |
| 97 | +@end |
| 98 | + |
| 99 | + |
| 100 | +//==================================================================== |
12 | 101 | @implementation CustomCell
|
| 102 | +@synthesize baseView; |
| 103 | +@synthesize slideView; |
| 104 | + |
13 | 105 | @synthesize nameLabel;
|
14 | 106 | @synthesize dateLabel;
|
15 | 107 | @synthesize descLabel;
|
16 | 108 | @synthesize imageView;
|
17 | 109 |
|
| 110 | + |
| 111 | +@synthesize button; |
| 112 | + |
18 | 113 | - (void)dealloc
|
19 | 114 | {
|
| 115 | + self.baseView = nil; |
| 116 | + self.slideView = nil; |
| 117 | + |
20 | 118 | self.nameLabel = nil;
|
21 | 119 | self.dateLabel = nil;
|
22 | 120 | self.descLabel = nil;
|
23 | 121 | self.imageView = nil;
|
24 | 122 | [super dealloc];
|
25 | 123 | }
|
26 | 124 |
|
| 125 | +- (void)setSelected:(BOOL)selected animated:(BOOL)animated |
| 126 | +{ |
| 127 | + // self selected |
| 128 | + // 0 0 => 0 |
| 129 | + // 0 1 => 1 |
| 130 | + // 1 0 => 0 |
| 131 | + // 1 1 => 0 |
| 132 | + BOOL realSelected = !self.selected && selected; |
| 133 | + [super setSelected:realSelected animated:animated]; |
| 134 | + self.baseView.selected = realSelected; |
| 135 | +} |
| 136 | + |
| 137 | +- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated |
| 138 | +{ |
| 139 | + UIColor* selectedColor = [UIColor whiteColor]; // default color |
| 140 | + if (highlighted) { |
| 141 | + selectedColor = [UIColor lightGrayColor]; |
| 142 | + } |
| 143 | + self.baseView.backgroundColor = selectedColor; |
| 144 | + [super setHighlighted:highlighted animated:animated]; |
| 145 | +} |
| 146 | + |
| 147 | +- (void)setSlideOpened:(BOOL)slideOpened animated:(BOOL)animated |
| 148 | +{ |
| 149 | + if (slideOpened == slideOpened_) { |
| 150 | + return; |
| 151 | + } |
| 152 | + slideOpened_ = slideOpened; |
| 153 | + |
| 154 | +// if (![self.subviews containsObject:self.slideView]) { |
| 155 | +// [self insertSubview:self.slideView atIndex:0]; |
| 156 | +// } |
| 157 | + |
| 158 | + if (animated) { |
| 159 | + if (slideOpened_) { |
| 160 | + // open slide |
| 161 | + [UIView animateWithDuration:0.2 |
| 162 | + animations:^{ |
| 163 | + CGRect frame = self.baseView.frame; |
| 164 | + frame.origin.x += frame.size.width; |
| 165 | + self.baseView.frame = frame; |
| 166 | + }]; |
| 167 | + |
| 168 | + } else { |
| 169 | + // close slide |
| 170 | + [UIView animateWithDuration:0.1 |
| 171 | + animations:^{ |
| 172 | + CGRect frame = self.baseView.frame; |
| 173 | + frame.origin.x = 0; |
| 174 | + self.baseView.frame = frame; |
| 175 | + }]; |
| 176 | + } |
| 177 | + } else { |
| 178 | + CGRect frame = self.baseView.frame; |
| 179 | + if (slideOpened_) { |
| 180 | + // open slide |
| 181 | + frame.origin.x += frame.size.width; |
| 182 | + |
| 183 | + } else { |
| 184 | + // close slide |
| 185 | + frame.origin.x = 0; |
| 186 | + } |
| 187 | + self.baseView.frame = frame; |
| 188 | + |
| 189 | + } |
| 190 | + |
| 191 | +} |
| 192 | + |
27 | 193 | @end
|
0 commit comments