Handling Touch Event in UILabel and hooking it up to an IBAction

后端 未结 4 750
旧巷少年郎
旧巷少年郎 2020-11-30 18:09

Ok, so I have a UILabel created in interface builder that displays some some default text of \"tap to begin\".

When the user taps the UILabel

4条回答
  •  失恋的感觉
    2020-11-30 18:57

    Check it out:

    UILabel *label = ...
    label.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture =
          [[UITapGestureRecognizer alloc] initWithTarget:self 
                                                  action:@selector(labelTap)];
    [label addGestureRecognizer:tapGesture];
    

    The trick is to enable user interaction.

提交回复
热议问题