Homework2 play cards8. showFront - think
• what is this meaning in UIImageView ?
• UIImageView has a property named image
• what is the implementation of show front
13年8月2⽇日星期五
12. The same policy for backImage
@interface CardView : UIImageView
@property UIImage * frontImage;
@property UIImage * backImage;
-(void) showFront;
-(void) showBack;
-(void) lock;
@end
13年8月2⽇日星期五
14. Testing Code - test showFront
-(void) testShowFront{
CardView * card = [CardView new];
card.frontImage = [UIImage imageNamed:@"front0.png"];
[card showFront];
if( ![card.frontImage isEqual:card.image]){
NSLog(@”show front not works”);
}
}
13年8月2⽇日星期五
15. Testing Code - test showBack
-(void) testShowBack{
CardView * card = [CardView new];
card.backImage = [UIImage imageNamed:@"back.png"];
[card showBack];
if( ![card.backImage isEqual:card.image]){
NSLog(@”show back not works”);
}
}
13年8月2⽇日星期五
19. Add unlock
@interface CardView : UIImageView
@property UIImage * frontImage;
@property UIImage * backImage;
-(void) showFront;
-(void) showBack;
-(void) lock;
-(void) unlock;
@end
13年8月2⽇日星期五
20. lock/Unlock - implementation
- (void)lock {
self.isLocked = YES;
self.layer.borderColor = [[UIColor blueColor]CGColor];
self.layer.borderWidth = 5.0;
}
- (void)unlock {
self.isLocked = NO;
self.layer.borderColor = [[UIColor blackColor]CGColor];
self.layer.borderWidth = 1.0;
}
change border colorisLocked ??????
13年8月2⽇日星期五
21. Add private property
• in CardView.m
@interface CardView()
@property BOOL isLocked;
@end
@implementation CardView
// ignored...
@end
13年8月2⽇日星期五
27. Call the method on all objects in array
[self.cards makeObjectsPerformSelector:@selector(setBackImage:)
withObject:[UIImage imageNamed:@"back"] ];
CardView CardView CardView CardView CardView
[cardView setBackImage:[UIImage imageNamed:@”back”]]
cards
13年8月2⽇日星期五
32. Class Diagram - Add new method
CarView
+frontImage
+backImage
-isLocked
showFront
showBack
lock
unlock
changeImage
13年8月2⽇日星期五
37. show front & show back
-(void) showFront{
if (self.isLocked) {
return;
}
self.image = self.frontImage;
self.isFront = YES;
}
-(void) showBack{
if (self.isLocked) {
return;
}
self.image = self.backImage;
self.isFront = NO;
}
13年8月2⽇日星期五
44. Segmented Control
0 1 2 3 4
CardView CardView CardView CardView CardView
cards
[cardView lock]
13年8月2⽇日星期五