次のコードを使用して、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