6

I'm trying to change the color of an UIButton's image when the user clicks on the UIButtonthrough Interface Builder without having to create a new image. These are the settings for the UIButton both Normal and Highlighted state:

enter image description here enter image description here

But the image keeps the same color.. What am I missing in order to make it work?

LS_
  • 6,763
  • 9
  • 52
  • 88
  • take 2 image instead .. 1 for selected and 1 for default – Bhavin Bhadani May 03 '16 at 13:30
  • 2
    @EICaptain I might end up using 2 images, but I'd like to know if it's possible to achieve what I want just using IB – LS_ May 03 '16 at 13:46
  • 1
    the reason u r used the same image for two different states – Anbu.Karthik May 03 '16 at 14:41
  • @Anbu.Karthik you can change the color of the image using the tint color of the UIButton, but I can't get it working using IB, you can check an example on this question: http://stackoverflow.com/questions/19829356/color-tint-uibutton-image – LS_ May 03 '16 at 14:43
  • 1
    Hey Signo! If you might switch to setting tint color in code, I can provide you a simple solution which I used. I prepared custom class that changed `tintColor` depends on the `isHighlighted` state. `class MenuButton: UIButton { override var isHighlighted: Bool { didSet { if isHighlighted == true { tintColor = .brightSkyBlue } else { tintColor = .paleGrey } tintColorDidChange() } } }` – A Widera Mar 09 '18 at 11:29
  • A Widera's comment should really be an answer! – Andy Weinstein Aug 03 '22 at 18:26

0 Answers0