我用:
- (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];
}
}
用于确定触摸我在 UILabel 中的属性文本中的某些链接。如果我在字符串中只使用英文字符,一切都很好——我接触到的字符可以精确地确定。但是,如果我尝试将阿拉伯语和英语结合在一个标签中,就像在屏幕上一样
并尝试触摸 aljaml.com 我得到 amnesty.com 的范围。我应该怎么办?