Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

NIAttributedLabel #358

Merged
merged 3 commits into from

2 participants

@migrant

Adding links after images, the AttributedLabel fall to detect link
touch and give the correct highlight rect

@migrant migrant closed this
@migrant migrant reopened this
@jverkoey jverkoey commented on the diff
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++;
@jverkoey Owner

Can you add a comment explaining what this is doing?

@migrant
migrant added a note

If I insert a image at index m then after it add a link at index n (i.e n > m), after drawing text the link location is added by 1 in attributed string because NIAttributedLabel insert a 0xFFFC into attributed string for every image. In this case, the link location is n+1 in attributed string but is still n in the NSArray detectedlinkLocations or explicitLinkLocations.
When touching a character before which there are images, CTLineGetStringIndexForPosition(line, relativePoint) returns the actual index but I must provide a original index for [self linkAtIndex:idx] to determine whether I touch a link.So I must know how many images before and calcute the correct index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jverkoey jverkoey merged commit 16e0ecc into from
@jverkoey
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 8, 2013
  1. @migrant

    Adding links after images, the AttributedLabel fall to detect link

    migrant authored
    touch and give the correct highlight rect
  2. @migrant

    S

    migrant authored
    D
  3. @migrant

    Revert "S"

    migrant authored
    This reverts commit 1b28a2f.
This page is out of date. Refresh to see the latest.
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++;
@jverkoey Owner

Can you add a comment explaining what this is doing?

@migrant
migrant added a note

If I insert a image at index m then after it add a link at index n (i.e n > m), after drawing text the link location is added by 1 in attributed string because NIAttributedLabel insert a 0xFFFC into attributed string for every image. In this case, the link location is n+1 in attributed string but is still n in the NSArray detectedlinkLocations or explicitLinkLocations.
When touching a character before which there are images, CTLineGetStringIndexForPosition(line, relativePoint) returns the actual index but I must provide a original index for [self linkAtIndex:idx] to determine whether I touch a link.So I must know how many images before and calcute the correct index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
+
+ }
+
+ 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;
}
}
}
Something went wrong with that request. Please try again.