自定义的View,View中有自定义的UILabel,然后UILabel添加了点击事件。
action中的方法tap,是UITapGestureRecognizer对象,通过sender获取当前的view,然后通过类型转换来获取UILabel。
代码如下:
UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(taptouch:)];
[label addGestureRecognizer:tap];
label.userInteractionEnabled = YES;
[self addSubview:label];
- (void)taptouch:(UITapGestureRecognizer *)sender
{
UILabel *label = (UILabel *)sender.view;
NSLog(@"label text is %@",label.text);
}
网友评论