@@ -29,18 +29,21 @@ - (id)initWithFrame:(CGRect)frame {
29
29
self.userInteractionEnabled = NO ;
30
30
self.contentMode = UIViewContentModeScaleAspectFit;
31
31
32
+ imageButton = [[UIButton alloc ] initWithFrame: CGRectZero];
33
+ [imageButton addTarget: self action: @selector (didTapSelf: ) forControlEvents: UIControlEventTouchUpInside];
34
+ [self addSubview: imageButton];
35
+
32
36
selectedIndicatorImageView = [[UIImageView alloc ] initWithFrame: CGRectZero];
37
+ selectedIndicatorImageView.alpha = 0.0 ;
33
38
selectedIndicatorImageView.image = [UIImage imageNamed: @" check.png" ];
34
39
[selectedIndicatorImageView sizeToFit ];
35
- selectedIndicatorImageView.hidden = YES ;
36
- [self addSubview: selectedIndicatorImageView];
37
-
38
- [self addTarget: self action: @selector (didTapSelf: ) forControlEvents: UIControlEventTouchUpInside];
40
+ [self addSubview: selectedIndicatorImageView];
39
41
}
40
42
return self;
41
43
}
42
44
43
45
- (void )dealloc {
46
+ [imageButton release ];
44
47
[selectedIndicatorImageView release ];
45
48
[activityIndicator release ];
46
49
[super dealloc ];
@@ -49,6 +52,7 @@ - (void)dealloc {
49
52
- (void )layoutSubviews {
50
53
[super layoutSubviews ];
51
54
55
+ imageButton.frame = self.bounds ;
52
56
activityIndicator.frame = CGRectMake ((self.bounds .size .width - activityIndicator.bounds .size .width )/2 ,
53
57
(self.bounds .size .height - activityIndicator.bounds .size .height )/2 ,
54
58
activityIndicator.bounds .size .width ,
@@ -81,8 +85,8 @@ - (void)didTapSelf:(id)sender {
81
85
#pragma mark - Public Methods
82
86
83
87
- (void )setImage : (UIImage*)image {
84
- [self setBackgroundImage: image
85
- forState: UIControlStateNormal];
88
+ [imageButton setBackgroundImage: image
89
+ forState: UIControlStateNormal];
86
90
}
87
91
88
92
- (void )setImageUrl : (NSString *)url {
@@ -119,35 +123,49 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated
119
123
NSLog (@" Index:%i selected:%i " , self.tag , selected);
120
124
#endif
121
125
122
- selectedIndicatorImageView.hidden = !isSelected;
123
- }
124
-
125
- - (void )setEditing : (BOOL )editing animated : (BOOL )animated
126
- {
127
- isEditing = editing;
128
-
129
126
if (animated) [UIView beginAnimations: nil context: nil ];
130
127
131
- if (isEditing)
128
+ if (isSelected)
132
129
{
133
- self.alpha = 0.8 ;
134
- }else
130
+ selectedIndicatorImageView.alpha = 1.0 ;
131
+ imageButton.alpha = 0.8 ;
132
+ }
133
+ else
135
134
{
136
- self.alpha = 1.0 ;
135
+ selectedIndicatorImageView.alpha = 0.0 ;
136
+ imageButton.alpha = 1.0 ;
137
137
}
138
-
139
138
if (animated) [UIView commitAnimations ];
140
-
141
- [self setSelected: NO animated: YES ];
139
+ }
140
+
141
+ - (void )setEditing : (BOOL )editing animated : (BOOL )animated
142
+ {
143
+ if (isEditing != editing) {
144
+ isEditing = editing;
145
+
146
+ if (animated) [UIView beginAnimations: nil context: nil ];
147
+
148
+ // if (isEditing)
149
+ // {
150
+ // imageButton.alpha = 0.8;
151
+ // }else
152
+ // {
153
+ // imageButton.alpha = 1.0;
154
+ // }
155
+
156
+ if (animated) [UIView commitAnimations ];
157
+
158
+ [self setSelected: NO animated: YES ];
159
+ }
142
160
}
143
161
144
162
#pragma mark - VCResponseFetchServiceDelegate Methods
145
163
146
164
-(void )didSucceedReceiveResponse : (NSObject <VCDataProcessorDelegate> *)response {
147
165
if ([response isKindOfClass: [VCImageResponseProcessor class ]]) {
148
166
UIImage *image = [(VCImageResponseProcessor*)response image ];
149
- [self setBackgroundImage: image
150
- forState: UIControlStateNormal];
167
+ [imageButton setBackgroundImage: image
168
+ forState: UIControlStateNormal];
151
169
152
170
}
153
171
}
0 commit comments