Skip to content

Commit 4295e1b

Browse files
committed
first version
1 parent 68be10e commit 4295e1b

File tree

9 files changed

+9617
-360
lines changed

9 files changed

+9617
-360
lines changed

CustomCellSample/CustomCellSample.xcodeproj/project.pbxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
4C5B913C13880813003415FA /* image06s.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4C5B913413880813003415FA /* image06s.jpg */; };
2727
4C5B913D13880813003415FA /* image07s.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4C5B913513880813003415FA /* image07s.jpg */; };
2828
4C5B913E13880813003415FA /* image08s.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4C5B913613880813003415FA /* image08s.jpg */; };
29+
4CC42CDB13B94BD500D20C78 /* FooterView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC42CDA13B94BD400D20C78 /* FooterView.m */; };
2930
/* End PBXBuildFile section */
3031

3132
/* Begin PBXFileReference section */
@@ -54,6 +55,8 @@
5455
4C5B913413880813003415FA /* image06s.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = image06s.jpg; sourceTree = "<group>"; };
5556
4C5B913513880813003415FA /* image07s.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = image07s.jpg; sourceTree = "<group>"; };
5657
4C5B913613880813003415FA /* image08s.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = image08s.jpg; sourceTree = "<group>"; };
58+
4CC42CD913B94BD400D20C78 /* FooterView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FooterView.h; path = ../FooterView.h; sourceTree = "<group>"; };
59+
4CC42CDA13B94BD400D20C78 /* FooterView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FooterView.m; path = ../FooterView.m; sourceTree = "<group>"; };
5760
/* End PBXFileReference section */
5861

5962
/* Begin PBXFrameworksBuildPhase section */
@@ -110,6 +113,8 @@
110113
4C5B912A13880441003415FA /* CustomCell.h */,
111114
4C5B912B13880441003415FA /* CustomCell.m */,
112115
4C5B912D13880453003415FA /* CustomCell.xib */,
116+
4CC42CD913B94BD400D20C78 /* FooterView.h */,
117+
4CC42CDA13B94BD400D20C78 /* FooterView.m */,
113118
);
114119
path = CustomCellSample;
115120
sourceTree = "<group>";
@@ -206,6 +211,7 @@
206211
4C5B911B1388041C003415FA /* CustomCellSampleAppDelegate.m in Sources */,
207212
4C5B91211388041C003415FA /* RootViewController.m in Sources */,
208213
4C5B912C13880441003415FA /* CustomCell.m in Sources */,
214+
4CC42CDB13B94BD500D20C78 /* FooterView.m in Sources */,
209215
);
210216
runOnlyForDeploymentPostprocessing = 0;
211217
};
@@ -318,6 +324,7 @@
318324
4C5B91291388041C003415FA /* Release */,
319325
);
320326
defaultConfigurationIsVisible = 0;
327+
defaultConfigurationName = Release;
321328
};
322329
/* End XCConfigurationList section */
323330
};

CustomCellSample/CustomCellSample/CustomCell.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@
99
#import <UIKit/UIKit.h>
1010

1111

12+
@class BaseView, SlideView;
1213
@interface CustomCell : UITableViewCell {
1314

15+
BOOL slideOpened_;
1416
}
17+
@property (nonatomic, retain) IBOutlet BaseView* baseView;
18+
@property (nonatomic, retain) IBOutlet SlideView* slideView;
19+
1520
@property (nonatomic, retain) IBOutlet UILabel* nameLabel;
1621
@property (nonatomic, retain) IBOutlet UILabel* dateLabel;
1722
@property (nonatomic, retain) IBOutlet UILabel* descLabel;
1823
@property (nonatomic, retain) IBOutlet UIImageView* imageView;
1924

25+
26+
@property (nonatomic, retain) IBOutlet UIButton* button;
27+
28+
29+
- (void)setSlideOpened:(BOOL)slideOpened animated:(BOOL)animated;
30+
2031
@end

CustomCellSample/CustomCellSample/CustomCell.m

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,185 @@
99
#import "CustomCell.h"
1010

1111

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+
//====================================================================
12101
@implementation CustomCell
102+
@synthesize baseView;
103+
@synthesize slideView;
104+
13105
@synthesize nameLabel;
14106
@synthesize dateLabel;
15107
@synthesize descLabel;
16108
@synthesize imageView;
17109

110+
111+
@synthesize button;
112+
18113
- (void)dealloc
19114
{
115+
self.baseView = nil;
116+
self.slideView = nil;
117+
20118
self.nameLabel = nil;
21119
self.dateLabel = nil;
22120
self.descLabel = nil;
23121
self.imageView = nil;
24122
[super dealloc];
25123
}
26124

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+
27193
@end

0 commit comments

Comments
 (0)