U could make an UIImage pointer which holds a specific image name. and then compare to this pointer.
Please elaborate, jnoxx. Cuz I'm not sure what solution you are proposing here. How can a UIImage pointer hold an image name when a UIImage pointer simply references a UIImage object which has no name property?U could make an UIImage pointer which holds a specific image name. and then compare to this pointer.
Please elaborate, jnoxx. Cuz I'm not sure what solution you are proposing here. How can a UIImage pointer hold an image name when a UIImage pointer simply references a UIImage object which has no name property?
UIImage *Image1 = [UIImage imageNamed:@"abc.png"];
if(youruiimageviewname.image == Image1){
//do stuff
}
I believe he meant.
Code:UIImage *Image1 = [UIImage imageNamed:@"abc.png"]; if(youruiimageviewname.image == Image1){ //do stuff }
UIImage *image = [UIImage imageNamed:@"whatever.jpg"];
if (image)
{ // Do whatever}
else {
//dayum, create a new UIImage pointer then!
}
there is no chance to wrote youruiimageviewname.image.
UIImage *image = [UIImage imageNamed:@"whatever.jpg"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
if (imageView.image == image) {
//wow, it's the same, i'm gonna do some kickass stuff here
} else {
//Damn, it isn't the same.. let's do something else..
}
Originally Posted by Nnavick
"there is no chance to wrote youruiimageviewname.image."
?
youruiimageviewname is where you would place your UIImageView name (your IBOutlet name for your UIImageView).
UIButton *btt;;
UIImage *buttonImage = [UIImage imageNamed:@"abc.png"];
if(btt.imageView.image==buttonImage) {
}
Step 1: Refer to the UIButton class reference.and how do I compare a UIButton image to UIImage ?
?Code:UIButton *btt;; UIImage *buttonImage = [UIImage imageNamed:@"abc.png"]; if(btt.imageView.image==buttonImage) { }
Step 1: Refer to the UIButton class reference.
Does it have an imageView property?
If not, then what properties or methods does it have that return the UIImage* type?
Maybe the imageForState or backgroundImageForState properties.
Step 2: Once you've determined the property or method to use on UIButton, determine how you wish to compare the UIImage pointers.
The obvious == operation only compares whether two object pointers are identical. It's possible to have images loaded from the same file whose object pointers are different. If your code is written so all loading of images uses UIImage imageNamed:, then that condition (two pointers with same image file but different value) probably won't happen.
Step 3: Once you have the proper method or property, and have decided on what you'll compare the images with, write the conditional statement.
Step 4: Debug your code.
If it works first time, great. If not, then determine whether any variables (such as the UIButton or UIImage) happen to be nil. Use the debugger for this.
can you write an example?