I'm creating UIButtons (type = UIButtonTypeCustom) with a custom background drawn by an artist; unfortunately UIButton is adding an unwanted 'well' effect around the backgroundImage (as specified via setBackgroundImage). Is there a way to disable the well? It's not a simple drop shadow, so messing with the CALayer properties doesn't seem to help. I realise I could use UIControl, but that's considerably more work, since I need to handle the label subview myself, and get the artist to produce highlighted versions of the artwork - UIButton is doing all that nicely, if I could only disable the well effect.
+1
A:
Put your image inside a UIImageView, and then position your UIButton on top of it. Use the "custom" style, which has no UI to it at all and is totally invisible.
If you want to change ("highlight") your button image when the button is hit, just change the image contained in the UIImageView in whatever method your UIButton targets.
Dan Ray
2010-10-26 11:57:48
That doesn't seem very elegant - and I'm already using the custom style, so the 'has no UI' statement seems incorrect to me. If I have to do the state-change graphics manually, I might as well use UIControl and be done with it.
James Turner
2010-10-26 12:25:05
I've tried this lots. Separating the image and the button really is the best solution I've found. If you want to encapsulate that in a UIControl subclass, that's fine, but unnecessary.
Dan Ray
2010-10-26 12:28:28