2
我想選擇特定的句子。我的段落由許多句子組成,每個句子都有一個索引,當我顯示並突出顯示整個句子(詩句)時點擊它。我已經取所需NSString
突出這樣的:如何在uitextview或uiimage的水龍頭上突出顯示特定的句子
CGPoint pos = [tap locationInView:self.textView];
//get location in text from textposition at point
UITextPosition *tapPos = [self.textView closestPositionToPoint:pos];
//fetch the word at this position (or nil, if not available)
UITextRange * wr =
[self.textView.tokenizer rangeEnclosingPosition:tapPos
withGranularity:UITextGranularitySentence
inDirection:UITextLayoutDirectionRight];
//fetch the word at this position (or nil, if not available)
UITextRange * wl =
[self.textView.tokenizer rangeEnclosingPosition:tapPos
withGranularity:UITextGranularitySentence
inDirection:UITextLayoutDirectionLeft];
if ([wr isEqual:wl]) {
NSLog(@"WORD: %@", [self.textView textInRange:wr]);
NSString *infoString = [self.textView textInRange:wr];
NSMutableAttributedString *attString =
[[NSMutableAttributedString alloc] initWithString:infoString];
NSInteger _stringLength = [infoString length];
UIColor *_black = [UIColor blackColor];
UIFont *font = [UIFont fontWithName:@"Helvetica-Bold"
size:30.0f];
[attString addAttribute:NSFontAttributeName
value:font
range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName
value:_black
range:NSMakeRange(0, _stringLength)];
}
其良好的..但問題是,它選擇了整行..我有阿拉伯文本,我必須突出從開始點到結束點的詩句(句子)。 –
@UmairTariq:嗨,即時通訊做出同樣的事情。我也必須做同樣的事情。突出整個經文。這是否完成?你能幫我在這裏嗎? –
@iOSDev我無法通過突出顯示文本來實現這一點..我通過獲取座標來突出顯示圖像部分來完成這項工作。 –