Image comparison in iOS 8 not working

I am using a button with multiple images, for example, after clicking a button, the image of that button changes, so I used something like this:

if(button.imageVIew.image ==[UIImage imageNamed:@"addFriendPressed.png"]){

    do something



This worked in iOS 7, not iOS8. Any solutions please?

- (BOOL)image:(UIImage *)image1 isEqualTo:(UIImage *)image2
    NSData *data1 = UIImagePNGRepresentation(image1);
    NSData *data2 = UIImagePNGRepresentation(image2);

    return [data1 isEqual:data2];



source to share

1 answer

Use isEqual :

if([button.imageVIew.image isEqual:[UIImage imageNamed:@"addFriendPressed.png"]]){
    do something



if([[button backgroundImageForState:UIControlStateNormal] isEqual: [UIImage imageNamed:@"addFriendPressed.png"]]){
    do something


or add category to UIImageView



All Articles