Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a UIView as the background of a UIButton?

I have a UIButton. Rather than giving it a background Image, I want to use a custom UIView object as the background. I realize I could do this by rendering the UIView into an image, then using that. But is there a better way?

I've looked at playing with the Button's view tree, but that seems to have undesirable side effects.

like image 587
William Jockusch Avatar asked Mar 14 '14 15:03

William Jockusch


1 Answers

To achieve the same, I usually do this:

Add subview to the parentView

Add a UIButton with clearColor to the parentView, with the same frame as the subview.

You can achieve the same by creating a custom UIView class that has this view and button as its properties.

like image 167
Nitin Alabur Avatar answered Nov 15 '22 00:11

Nitin Alabur