Ios 将当前图像与图像进行比较
我正在检查UIButton中的图像是否正确。我测试了这段代码,我知道这是同一个图像,但不工作Ios 将当前图像与图像进行比较,ios,objective-c,iphone,uibutton,xcode6,Ios,Objective C,Iphone,Uibutton,Xcode6,我正在检查UIButton中的图像是否正确。我测试了这段代码,我知道这是同一个图像,但不工作 UIButton *myButton = sender; if ([myButton.currentImage isEqual: [UIImage imageNamed:@"icon_ImageBox_disabled.png"]]) { NSLog("is the same image"); } 你们知道为什么这不起作用,或者当我比较同一张图片时为什么不起作用吗 默认实现
UIButton *myButton = sender;
if ([myButton.currentImage isEqual:
[UIImage imageNamed:@"icon_ImageBox_disabled.png"]])
{
NSLog("is the same image");
}
你们知道为什么这不起作用,或者当我比较同一张图片时为什么不起作用吗
默认实现只是比较指针
图像是否保证具有相同的名称,或者您正在寻找视觉比较?我正在测试代码,它们具有相同的图像我感觉图像的
isEqual
只是检查两个指针是否相等,没有任何东西保证imageNamed
将返回具有相同名称的相同对象。可能,但不一定。尝试使用NSLog(@“%p”,myButton.currentImage)
打印指针。你厌倦了谷歌搜索“如何比较图像”了吗?
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");
}