Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UILabel有触摸法吗?_Objective C_Ios_Cocoa Touch_Uilabel_Touch Event - Fatal编程技术网

Objective c UILabel有触摸法吗?

Objective c UILabel有触摸法吗?,objective-c,ios,cocoa-touch,uilabel,touch-event,Objective C,Ios,Cocoa Touch,Uilabel,Touch Event,如果有人触摸了预先声明的ui标签,我想做一个动作,比如: if (label is touched) { my actions; } 有什么方法/方法可以做到这一点吗?默认情况下,UILabel未配置为接受触摸输入。但是,如果使用ui按钮并将其设置为具有自定义外观,则可以使其看起来像(单行)标记并使其响应触摸事件。您需要确保userinteractionenabled设置为YES,然后您可以覆盖触摸开始:withEvent:您可以使用手势识别器: - (void)someSetupMe

如果有人触摸了预先声明的
ui标签
,我想做一个动作,比如:

if (label is touched) {
    my actions;
}

有什么方法/方法可以做到这一点吗?

默认情况下,
UILabel
未配置为接受触摸输入。但是,如果使用
ui按钮
并将其设置为具有自定义外观,则可以使其看起来像(单行)标记并使其响应触摸事件。

您需要确保userinteractionenabled设置为YES,然后您可以覆盖触摸开始:withEvent:您可以使用手势识别器:

- (void)someSetupMethod {
    // ...
    label.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture = \
    [[UITapGestureRecognizer alloc]
     initWithTarget:self action:@selector(didTapLabelWithGesture:)];
    [label addGestureRecognizer:tapGesture];
    [tapGesture release];
}

- (void)didTapLabelWithGesture:(UITapGestureRecognizer *)tapGesture {
    // ...
}

您可以将其子类化并覆盖触摸方法。您可能希望覆盖
touchesend:withEvent:


或者只需使用UIButton。

只需为UILabel类添加一个类别,并将您的方法添加到其中

这真的很容易做到!谢谢如果我有多个标签,那么如何识别哪个标签被点击???