【发布时间】:2013-07-24 06:48:32
【问题描述】:
我可以使用以下代码成功地将点击手势添加到 UITextView 的一部分:
UITextPosition *pos = textView.endOfDocument;// textView ~ UITextView
for (int i=0;i<words*2-1;i++){// *2 since UITextGranularityWord considers a whitespace to be a word
UITextPosition *pos2 = [textView.tokenizer positionFromPosition:pos toBoundary:UITextGranularityWord inDirection:UITextLayoutDirectionLeft];
UITextRange *range = [textView textRangeFromPosition:pos toPosition:pos2];
CGRect resultFrame = [textView firstRectForRange:(UITextRange *)range ];
UIView* tapViewOnText = [[UIView alloc] initWithFrame:resultFrame];
[tapViewOnText addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(targetRoutine)]];
tapViewOnText.tag = 125;
[textView addSubview:tapViewOnText];
pos=pos2;
}
我希望在UILabel 中模仿相同的行为。问题是,UITextInputTokenizer(用于标记单个单词)在UITextInput.h 中声明,并且只有UITextView 和UITextField符合UITextInput.h; UILabel 没有。
有解决办法吗??
【问题讨论】:
-
你好朋友,你有没有检查过UILabel的用户交互行为,因为默认情况下用户交互是UIlabel的NO,你必须设置它YES。让我知道它是否有效。!!!
-
对整个 UILabel 的操作不是问题,它是 UILabel 的“一部分”。
标签: iphone ios uilabel uitapgesturerecognizer uitextinput