Reputation: 111
I use:
- (void)handleLinksTouch:(CGPoint)touchPoint {
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:self.attributedString];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager:layoutManager];
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:self.frame.size];
textContainer.lineFragmentPadding = 0;
[layoutManager addTextContainer:textContainer];
NSUInteger charIndex = [layoutManager characterIndexForPoint:touchPoint inTextContainer:textContainer fractionOfDistanceBetweenInsertionPoints:NULL];
NSDictionary *charAttributes = [self.attributedString attributesAtIndex:charIndex effectiveRange:NULL];
TVMessageLink *link = charAttributes[TVLinkAttributeName];
if ([self.delegate respondsToSelector:@selector(linkLabel:didSelectLink:)]) {
[self.delegate linkLabel:self didSelectLink:link];
}
}
for determination of touching on some link in my attributed text in UILabel. If I use only English characters in a string, all is well - the character that I've touched determining precisely. But if I try to combine Arabic and English in one label as in the screen
and try to touch in aljaml.com I get the range of amnesty.com. What should I do?
Upvotes: 1
Views: 809
Reputation: 26
Your solution works based on assuming UILabel using same layout options with you, it's not safe. Try UITextView / TTTAttributedLabel or My GSAttributedLabel for link interaction. Hoping to be helpful.
Upvotes: 0