I need to compare a color name. I have this code but it doesn't work =(
What should I do?
-(IBAction)buttonSelect:(id)sender {
if ([sender color] == [UIColor redColor]) {
// do something.
}
}
Thanks!
I need to compare a color name. I have this code but it doesn't work =(
What should I do?
-(IBAction)buttonSelect:(id)sender {
if ([sender color] == [UIColor redColor]) {
// do something.
}
}
Thanks!
Try this:
if ([[sender titleColorForState:UIControlStateNormal] isEqual:[UIColor redColor]])
{
// do something
}
This is how you compare objects in objective-c, as objects are pointers and you can't compare pointers with ==
. I'd advise you to look into this