Skip to content
Browse files

Adding links after images, the AttributedLabel fall to detect link

touch and give the correct highlight rect
  • Loading branch information...
1 parent 53cb2b6 commit 5344dc761dfc66bf929c2037213015b9f7de5716 @migrant migrant committed Mar 8, 2013
Showing with 13 additions and 2 deletions.
  1. +13 −2 src/attributedlabel/src/NIAttributedLabel.m
View
15 src/attributedlabel/src/NIAttributedLabel.m
@@ -788,9 +788,20 @@ - (NSTextCheckingResult *)linkAtPoint:(CGPoint)point {
CGPoint relativePoint = CGPointMake(point.x-CGRectGetMinX(rect),
point.y-CGRectGetMinY(rect));
CFIndex idx = CTLineGetStringIndexForPosition(line, relativePoint);
- foundLink = [self linkAtIndex:idx];
+
+ NSUInteger offset = 0;
+ for (NIAttributedLabelImage *labelImage in self.images) {
+ if (labelImage.index < idx) {
+ offset++;
+ }
+
+ }
+
+ foundLink = [self linkAtIndex:idx - offset];;
if (foundLink) {
- return foundLink;
+ NSTextCheckingResult *result = [NSTextCheckingResult linkCheckingResultWithRange:NSMakeRange(foundLink.range.location + offset, foundLink.range.length) URL:foundLink.URL];
+
+ return result;
}
}
}

0 comments on commit 5344dc7

Please sign in to comment.
Something went wrong with that request. Please try again.