Search code examples
iosobjective-cuibuttontint

Change colour of dark grey highlight when holding down custom UIButton?


I have a custom UIButton which is a cloud, transparent black and white .png file, with no down state, just one image. When tapping and holding the finger over it, it turns dark grey. I'm trying to change that dark grey to something a little less oppressive. The button is out in the open in a view, not in a tab bar, tool bar, or navigation controller.

I've already tried setting tintColor (which the documentation helpfully informs me is only suitable for 'some' types of buttons, which no indication as to which).

I've also tried changing everything I can find in Interface Builder relating to highlight colours, default states, etc. Nothing has made a difference at all.

I've even tried setting the button's own image for its UIControlStateHighlighted state, but even this causes the dark grey overlay to appear when I hold my finger over it.

How can I change that colour? I've looked at numerous other issues here on SO and have been unable to find a solution that works for me. Any help would be greatly appreciated!

EDIT: I Solved the problem using a category of UIImage which adds a method that uses CoreGraphics to apply a tint to a provided UIImage. I then set THAT image as the highlight, and all is well. Seems a lot of hoop-la to change a colour Apple should've let us change, but c'est la vie.


Solution

  • You said you set a custom image for the UIControlStateHighlighted state. This should disable the default behaviour.

    If you still have problems you can disable this effect by setting the adjustsImageWhenHighlighted property to NO and use whatever custom effect you want.