将 UIButton 当前图像与图像进行比较
Compare UIButton current image with a image
我正在尝试检查图像是否是 UIButton 中的正确图像。我已经测试了这段代码,我知道是同一张图片,但不起作用。
UIButton *myButton = sender;
if ([myButton.currentImage isEqual:
[UIImage imageNamed:@"icon_ImageBox_disabled.png"]])
{
NSLog("is the same image");
}
你们中有人知道为什么这不起作用或者为什么当我比较相同的图像时不起作用吗?
The default implementation just compares pointers.
UIButton *myButton = sender;
NSData *data1 = UIImagePNGRepresentation(myButton.currentImage);
NSData *data2 = UIImagePNGRepresentation([UIImage imageNamed:@"icon_ImageBox_disabled.png""]);
if ([data1 isEqual:data2])
{
NSLog(@"is the same image");
}else{
NSLog(@"is not the same image");
}
我正在尝试检查图像是否是 UIButton 中的正确图像。我已经测试了这段代码,我知道是同一张图片,但不起作用。
UIButton *myButton = sender;
if ([myButton.currentImage isEqual:
[UIImage imageNamed:@"icon_ImageBox_disabled.png"]])
{
NSLog("is the same image");
}
你们中有人知道为什么这不起作用或者为什么当我比较相同的图像时不起作用吗?
The default implementation just compares pointers.
UIButton *myButton = sender;
NSData *data1 = UIImagePNGRepresentation(myButton.currentImage);
NSData *data2 = UIImagePNGRepresentation([UIImage imageNamed:@"icon_ImageBox_disabled.png""]);
if ([data1 isEqual:data2])
{
NSLog(@"is the same image");
}else{
NSLog(@"is not the same image");
}