这是一个标签属性,你也可以给一个独特的标签也标签。
UILabel *label = =[UILabel alloc]init];
label.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture =
[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap)] autorelease];
[label addGestureRecognizer:tapGesture];
- 以下是标签触摸的方法。
//touches begin method
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;
//touches end method
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if (CGRectContainsPoint([self.site frame], [touch locationInView:self.view])){
//do whatever you want
}
}
//touches move method
- (void)touchesMove:(NSSet *)touches withEvent:(UIEvent *)event;