的一部分,我可以成功添加自来水手势的UITextView的一部分与下面的代码:双击手势上的UILabel
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的用户交互行为,因为默认情况下用户交互是NO的UILabel的,你必须把它YES.Let我知道的是它的工作或不。!!! – NiravPatel
对整个UILabel的操作不是问题,它是UILabel的一部分。 – n00bProgrammer
请检查http://stackoverflow.com/questions/8811909/getting-the-word-touched-in-a-uilabel-uitextview/21577829#21577829 – TheTiger