tôi có thể thành công thêm cử chỉ tap vào một phần của UITextView với đoạn mã sau:Tap Gesture trên một phần của 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;
}
Tôi muốn bắt chước các hành vi tương tự trong một UILabel
. Vấn đề là, UITextInputTokenizer
(được sử dụng để mã hóa từng từ riêng lẻ) được khai báo trong UITextInput.h
và chỉ UITextView
& UITextField
phù hợp với UITextInput.h
; UILabel
thì không. Có cách nào khác không?
hi bạn bè, có bạn kiểm tra các hành vi tương tác người dùng của UILabel, bởi vì userinteraction mặc định là NO của UILabel, bạn sẽ phải thiết lập nó YES.Let tôi biết là nó làm việc hay không.!!! – NiravPatel
Hành động trên toàn bộ UILabel không phải là vấn đề, đó là 'một phần' của UILabel. – n00bProgrammer
Vui lòng kiểm tra http://stackoverflow.com/questions/8811909/getting-the-word-touched-in-a-uilabel-uitextview/21577829#21577829 – TheTiger