0

I have 4 cards and I can flip my cards, I want to check if my images is the same show 2 images and if it's not back the flip,

would you please give me some tutorial or sample code;

Thanks in advance!

Edit:

Here is my images:

UIImage *img1 = [UIImage imageNamed:@"card_front.png"];

[self addCardAtX:90 y:120 andFrontImage:img1 andTag:1];
[self addCardAtX:230 y:120 andFrontImage:img1 andTag:1];
[self addCardAtX:90 y:340 andFrontImage:img1 andTag:1];
[self addCardAtX:230 y:340 andFrontImage:img1 andTag:1];



- (void)addCardAtX:(CGFloat)x y:(CGFloat)y andFrontImage:(UIImage *) img1 andTag:(int)tag
{

UIImage *img2= [UIImage imageNamed:@"card_back.png"];


CardView *cv = [[CardView alloc] initWithFrontImage:img1 backImage:img2];


CGRect f = cv.frame;
f.origin.x = x-(f.size.width/2.0);
f.origin.y = y-(f.size.height/2.0);
cv.frame = f;


[self.view addSubview:cv];
}
Anoop Vaidya
  • 45,475
  • 15
  • 105
  • 134
  • Yes, use something else other than the images. What you are trying to do is hard. Use the tags or something else. – Fogmeister Jan 29 '13 at 14:44
  • @adam: the more tags, more people will see. more answer, fast answer, super answer. – Anoop Vaidya Jan 29 '13 at 14:45
  • @AKV thanks for your advice –  Jan 29 '13 at 14:49
  • @Fogmeister do you know any tutorial? for filp card images and compare them –  Jan 29 '13 at 14:50
  • No, but presumably you have some code that means "load image x" or "load image y" for a specific card. Well use THAT information to see if the cards match, not the images. – Fogmeister Jan 29 '13 at 14:55

2 Answers2

1

You can Compare image by its NAME or URL/Path But in objective-c you can also compare two objects, By,

if ([object1 isEqual:object2])

take BOOL variable imgCompare=NO; and check condition

if([Imgobject1 isEqual:ImgObject2])
  imgCompare=YES;
else
  imgCompare=NO;

Here is best Question of related discussion and also check This Link.

Thanks :)

Community
  • 1
  • 1
iPatel
  • 41,165
  • 13
  • 109
  • 131
0

You can check if images are equal buy using...

BOOL imagesAreTheSame = [image1 isEqual:image2];
Fogmeister
  • 70,181
  • 37
  • 189
  • 274