NIAttributedLabel #358

Merged
merged 3 commits into from Mar 26, 2013

Conversation

Projects
None yet
2 participants
Contributor

migrant commented Mar 8, 2013

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

migrant added some commits Mar 8, 2013

migrant closed this Mar 8, 2013

migrant reopened this Mar 8, 2013

@jverkoey jverkoey commented on the diff Mar 14, 2013

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

jverkoey Mar 14, 2013

Owner

Can you add a comment explaining what this is doing?

@migrant

migrant Mar 14, 2013

Contributor

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.

@jverkoey jverkoey added a commit that referenced this pull request Mar 26, 2013

@jverkoey jverkoey Merge pull request #358 from migrant/master
NIAttributedLabel
16e0ecc

@jverkoey jverkoey merged commit 16e0ecc into jverkoey:master Mar 26, 2013

Owner

jverkoey commented Mar 26, 2013

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment