How can I determine if a UILabel was touched?

前端 未结 6 1314
天命终不由人
天命终不由人 2020-12-25 08:39

I am trying to determine if a UILabel was touched and if so do something. Give ..

.
.
.
UILabel * site = [[UILabel alloc] initWithFrame:CGRectMake(0, 185, 32         


        
6条回答
  •  攒了一身酷
    2020-12-25 09:10

    You can do this without overriding touchesBegan. Use gesture recognizers.

    UILabel *label = ...;
    label.userInteractionEnabled = YES;
    UITapGestureRecognizer *recognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)] autorelease];
    
    [label addGestureRecognizer:recognizer];
    
    - (void)tapAction {
      NSLog(@"tap performed");
    }
    

提交回复
热议问题