rjgonzo
rjgonzo

Reputation: 1761

Make UIView work like a UIButton

I built a Custom Cell in IB and in it created a view that represents a button. It has Labels and ImageViews in it.

I want to know if there is a way to make that view act like a button. That is, show a shadow and call a method when is pressed.

Upvotes: 0

Views: 1475

Answers (3)

Herz Rod
Herz Rod

Reputation: 831

You can use UITapGestureRecognizer and pass the event through a delegate or use UIControl which is a subclass of UIView but with UIButton tap events like touchUpInside and so, and then pass the event with a delegate to your view

Upvotes: 0

Mundi
Mundi

Reputation: 80265

Yes. Just implement tableView:didSelectRowAtIndexPath: and you can do everything you could do in a button action @selector.

As for the shadow and the rounded rectangle button feel, if you use a single cell in a section with UITableViewStyleGrouped, it will be pretty close.

Upvotes: 2

PengOne
PengOne

Reputation: 48398

The best is to make it a button. You can use UIButtonTypeCustom and set the background to the cell you've created.

Upvotes: 1

Related Questions