开发者

Make UIView work like a UIButton

开发者 https://www.devze.com 2023-04-03 05:45 出处:网络
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 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 开发者_StackOverflow中文版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.


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消