Ios 将子字符串作为超链接的最佳工作方法是什么?

Ios 将子字符串作为超链接的最佳工作方法是什么?,ios,objective-c,tttattributedlabel,Ios,Objective C,Tttattributedlabel,我正在使用TSLabel。它在iOS 10.2和更低版本中运行得非常好,但在iOS 10.3中不起作用。我还尝试使用tttatTributedLabel,但由于某种原因,该框架在其方法之一中崩溃。现在我被卡住了。我不知道我到底应该用什么。在TSLabel中有一种方法 - (void) layoutManager: (NSLayoutManager *) layoutManager didCompleteLayoutForTextContainer: (NSTextContainer *) tex

我正在使用
TSLabel
。它在iOS 10.2和更低版本中运行得非常好,但在iOS 10.3中不起作用。我还尝试使用
tttatTributedLabel
,但由于某种原因,该框架在其方法之一中崩溃。现在我被卡住了。我不知道我到底应该用什么。在
TSLabel
中有一种方法

- (void) layoutManager: (NSLayoutManager *) layoutManager didCompleteLayoutForTextContainer: (NSTextContainer *) textContainer atEnd: (BOOL)layoutFinishedFlag {
// search for our custom label attribute - if we have it we'll tell it about link bounds!
TSLabel* label = [[self attribute: TSLabelAttributeName
                         atIndex: 0
                  effectiveRange: nil] object];

if ( label != nil && [label isKindOfClass: [TSLabel class]] )
{
    CGRect containerGlyphBounds = [layoutManager boundingRectForGlyphRange: [layoutManager glyphRangeForTextContainer: textContainer] inTextContainer: textContainer];

    // determine the bounds of each link and record that information with the TSLabel
    NSMutableSet* links = [NSMutableSet new];
    [self enumerateAttribute: TSLinkAttributeName
                     inRange: NSMakeRange(0, self.length)
                     options: 0
                  usingBlock: ^(NSURL* url, NSRange range, BOOL *stop) {

                      if ( url != nil )
                      {
                          TSLinkInfo* link = [TSLinkInfo new];
                          link.url = url;
                          link.range = range;

                          NSRange glyphRange = [layoutManager glyphRangeForCharacterRange: range actualCharacterRange: nil];
                          CGRect bounds = [layoutManager boundingRectForGlyphRange: glyphRange inTextContainer: textContainer];
                          link.bounds = CGRectOffset(bounds, 0, (label.bounds.size.height-containerGlyphBounds.size.height)/2);

                          [links addObject: link];
                      }
                  }];

    label.links = links;
}
}
它不仅在iOS 10.3中被调用,而且在
ttributedLabel
的情况下,如果我创建新项目并将相同的代码放在我的项目中,框架可以正常工作。此
TTTAttributedLabel
仅在我的项目中崩溃。它以以下方式崩溃:

- (NSArray *) links {
return [_linkModels valueForKey:@"result"];
}

LinkModels
变成了
NSZombie

在iOS 10.3中,NSAttributedString有一些bug,也许这就是造成问题的原因。崩溃是什么,你能分享它和代码吗?你可以使用
NSDataDetector
获取字符串中链接的范围。然后,您可以使用这些范围为链接加下划线。使用
UITapgestureRecognitizer
检测点击,如果点击在链接范围内,您可以执行下一步。@Koen您的第一条评论是询问
TSLabel
库还是
TTtatAttributedLabel
?我想做一些像这样的事情你好,请点击这里。因此,这里将有一个链接,有机会有电话号码也有。如果我使用
uitappesturerecognizer
,我会有那种色调感觉吗?就像我们在
UIButton
?我不使用那些库,只使用
UILabel
attributedString
属性。你能帮我解决这个问题吗?我的意思是如何直接处理
attributedString
?iOS 10.3中的
NSAttributedString
存在一些错误,可能正是这些错误导致了您的问题。崩溃是什么,你能分享它和代码吗?你可以使用
NSDataDetector
获取字符串中链接的范围。然后,您可以使用这些范围为链接加下划线。使用
UITapgestureRecognitizer
检测点击,如果点击在链接范围内,您可以执行下一步。@Koen您的第一条评论是询问
TSLabel
库还是
TTtatAttributedLabel
?我想做一些像这样的事情你好,请点击这里。因此,这里将有一个链接,有机会有电话号码也有。如果我使用
uitappesturerecognizer
,我会有那种色调感觉吗?就像我们在
UIButton
?我不使用那些库,只使用
UILabel
attributedString
属性。你能帮我解决这个问题吗?我的意思是如何直接使用
attributedString