diff --git a/YYText/YYLabel.m b/YYText/YYLabel.m index 7a8e829a..1e465862 100755 --- a/YYText/YYLabel.m +++ b/YYText/YYLabel.m @@ -613,7 +613,8 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { YYTextAction tapAction = _highlight.tapAction ? _highlight.tapAction : _highlightTapAction; if (tapAction) { YYTextPosition *start = [YYTextPosition positionWithOffset:_highlightRange.location]; - YYTextPosition *end = [YYTextPosition positionWithOffset:_highlightRange.location + _highlightRange.length affinity:YYTextAffinityBackward]; + NSInteger endOffset = MIN(_innerLayout.visibleRange.length, _highlightRange.location + _highlightRange.length); + YYTextPosition *end = [YYTextPosition positionWithOffset:endOffset affinity:YYTextAffinityBackward]; YYTextRange *range = [YYTextRange rangeWithStart:start end:end]; CGRect rect = [self._innerLayout rectForRange:range]; rect = [self _convertRectFromLayout:rect];