Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subclass UIButton or inherit from UIControl?

Tags:

uikit

iphone

ios5

I have an element that needs to behave like UIButton but it has several (3) text labels visible at once and multiple UIImages in the same bounding box. It's really a view with a bunch of different other UIViews and labels that needs to look and act like a button but with more custom placement of these elements than the standard UIButton.

Is it better to inherit from UIButton to accomplish this or is UIControl the one to inherit from?

When the element is tapped, I do want to mimic all of the highlighting effects (if it's UILabel, show the highlight text color, etc) as well.

like image 492
Jonas Gardner Avatar asked Jan 16 '12 17:01

Jonas Gardner


1 Answers

As long as it doesn't matter which part of your button content gets tapped to activate it's functions you could compose a UIButton along with all the UILabel, UIImageViews you need.

You could easily inherit from UIView, place all of the above inside and place your transparent UIButton on top of everything to get the events you need (setting yourself as the target for that button and implementing some delegate to notify about selection).

like image 51
Ignacio Inglese Avatar answered Sep 22 '22 07:09

Ignacio Inglese