UILabel + touchDown

时间:2010-11-11 18:50:02

标签: iphone xcode ios4

是否可以为UILabel实施触地得分?

3 个答案:

答案 0 :(得分:5)

UILabelUIView的子类,它本身是UIResponder的子类;因此,绝对有可能制作一个响应触摸的标签。只需创建UILabel的新子类并实现以下方法:

– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:

所以,如果你想在触摸开始时发生某些事情,你可以在-touchesBegan:withEvent:中进行。

如果创建一个新的子类对你来说过于苛刻,那么我建议按照@JustSid的建议并使用UIButton来完成任务。

答案 1 :(得分:5)

UILabel默认情况下userInterationEnabled设置为NO。

[label setUserInteractionEnabled:YES];
[label addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(touchedLabel:)]];


- (void)touchedLabel:(UIGestureRecognizer *)gesture {
NSLog(((UILabel*)gesture.view).text);
]

答案 2 :(得分:-3)

不,那不可能。但是你可以使用带有UIButtonTypeCustom的UIButton作为此任务的类型。

相关问题