In my app, I have a UIView which will drawrect according to user touch. It is meant to be used as a signature box. When the user is finished "drawing", they hit accept and the app continues. However, I would like to check if the UIView was actually drawn in, e.g. it isn't just blank. I tried making another empty UIImageView and checking to see if their image was equal but failed. Here is what I tried:
Note: signatureBox is the subclass of UIView which you can draw in. I save the signature, and compare it to the image in a blank UIImageView.
viewDidLoad{
UIGraphicsBeginImageContext(self.signatureBox.bounds.size);
[self.signatureBox.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(image);
self.blankImage.image = [UIImage imageWithData:imageData];
}
mySaveMethod{
UIGraphicsBeginImageContext(self.signatureBox.bounds.size);
[self.signatureBox.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(image);
self.signatureImage = [UIImage imageWithData:imageData];
if(self.signatureImage == self.blankImage.image){
NSLog(@"Blank");
}
else{
NSLog(@"not blank");
}
}
this nslogs "not blank" every time regardless of whether I draw in the the signatureBox or not. Any idea why?