UILabel是否有触摸方法?

| 如果有人触摸了预先定义的“ 0”字,我想采取措施,例如:
if (label is touched) {
    my actions;
}
有没有这样做的方法/方式?     
已邀请:
        您可以使用手势识别器:
- (void)someSetupMethod {
    // ...
    label.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture = \\
    [[UITapGestureRecognizer alloc]
     initWithTarget:self action:@selector(didTapLabelWithGesture:)];
    [label addGestureRecognizer:tapGesture];
    [tapGesture release];
}

- (void)didTapLabelWithGesture:(UITapGestureRecognizer *)tapGesture {
    // ...
}
    
        默认情况下,
UILabel
未配置为接受触摸输入。但是,如果改用
UIButton
并将其设置为具有自定义外观,则可以使其看起来像(单行)标签,并使它响应触摸事件。     
        您可以将其子类化并覆盖touch方法。您可能想覆盖
touchesEnded:withEvent:
。 或者只是使用UIButton。     
        您需要确保将userinteractionenabled设置为YES,然后才能覆盖ѭ6     
        只需为UILabel类添加一个类别,然后向其中添加您的方法即可。     

要回复问题请先登录注册