UILabel:在标签上使用userInteractionEnabled方法 [英] UILabel: Using the userInteractionEnabled method on a label

查看:157
本文介绍了UILabel:在标签上使用userInteractionEnabled方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人在UILabel上使用了userInteractionEnabled方法来允许标签像一个按钮(或者只是触发一个方法)。任何帮助将非常感谢。干杯!

I am wondering if anyone has used the userInteractionEnabled method on a UILabel to allow the label to act like a button (or just to fire off a method). Any help would be greatly appreciated. Cheers!

更新(4/30/09 @ 1:07pm)澄清:我有一个标准的InfoButton,在它旁边我想放置一个标签,设置,我想标签的功能像按钮(翻转到一个设置屏幕。所以,基本上我需要绑定已定义的showSettinsView到infoLabel标签;用户点击infoButton或infoLabel和方法触发。

Update (4/30/09 @1:07pm) Clarification: I have a standard InfoButton and next to it I want to place a label with the text "settings" and I would like the label to function like the button (which flips over to a settings screen. So, basically I need to tie the already defined showSettinsView to the "infoLabel" label; a user clicks on the infoButton or infoLabel and the method fires off.

infoButton已经工作,并且正在使用IBAction触发方法。我想知道如何连接标签来实现相同的方法

The infoButton is already working and is using an IBAction to trigger the method. I would like to know how to wire up the label to implement the same method. That is all. Cheers!

推荐答案

userInteractionEnabled 不是方法但是我想你会设置为 YES 允许事件通过 UIView

userInteractionEnabled is not a method but a property. But I think you will want to set this to YES to allow events to get through to the UIView superview.

您可能想要覆盖 touch的 touchesBegan:withEvent:包含您的 UIButton UILabel 子视图

What you might want to do is override the touchesBegan:withEvent: method of the UIView that contains your UIButton and UILabel subviews.

在此方法中,测试 UITouch 触摸是否位于 UILabel

Within this method, test if any of the UITouch touches fall inside the bounds of the UILabel.

也就是说, CGPoint 元素 [touch locationInView] CGRect 元素 [infoLabel bounds] 相交查看函数 CGRectContainsPoint 以运行此测试。

That is, does the CGPoint element [touch locationInView] intersect with with the CGRect element [infoLabel bounds]? Look into the function CGRectContainsPoint to run this test.

如果是这样,则触发 UIButton

这篇关于UILabel:在标签上使用userInteractionEnabled方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆