0

Based on this: Several images on one UIButton

I can add images on UIButton, but I can't show the highlighted state UIImageView inside the UIButton.

Have set the highlighted image as follows:

imageOneOnButton.image = [UIImage imageNamed:@"option-unchecked"];
imageOneOnButton.highlightedImage = [UIImage imageNamed:@"option-checked"];

imageTwoOnButton.image = [UIImage imageNamed:@"option-unchecked"];
imageTwoOnButton.highlightedImage = [UIImage imageNamed:@"option-checked"];

Unfortunately on its action:

sender.highlighted = YES // or NO doesn't work
sender.imageView.highlighted = YES // or NO doesn't work as well

Is there any way that I can simulate this,

[button setImage:[UIImage imageNamed:@"option-unchecked"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"option-unchecked"] forState:UIControlStateHighlighted];

button.highlighted = YES // or NO <-- works!

using my approach?

Community
  • 1
  • 1
ndraniko
  • 814
  • 1
  • 8
  • 14
  • So you have two image views inside one button? You may need to subclass your button and override its `setHighlighted:` setter to call `setHighlighted:` on each of its imageviews. The reason `sender.imageView.highlighted = YES` isn't working is because (I assume) that neither imageview is associated with the button's built-in `.imageView` property. – user2320861 Apr 07 '15 at 15:49
  • @user2320861 I guess you're right. Thanks, will try it. – ndraniko Apr 07 '15 at 15:55
  • Ok, if it works let me know and I'll post it as an answer that you can accept. – user2320861 Apr 07 '15 at 15:58
  • @user2320861 it works. you might want to post it as an answer. thanks. – ndraniko Apr 07 '15 at 16:31

1 Answers1

0

So you have two image views inside one button? You may need to subclass your button and override its setHighlighted: setter to call setHighlighted: on each of its imageviews.

The reason sender.imageView.highlighted = YES isn't working is because (I assume) that neither imageview is associated with the button's built-in .imageView property

user2320861
  • 1,391
  • 2
  • 11
  • 28