我正在使用TSLabel
。它适用于iOS 10.2及更低版本,但在iOS 10.3中无效。我也尝试使用TTTAttribuedLabel
,但由于某种原因,框架在其中一个方法中崩溃。现在我被卡住了。我不知道究竟应该用什么。在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和TTTAtributedLabel
的情况下不会调用它。如果我创建新项目并将相同的代码放在我的项目中,框架工作正常。这个TTTAttributedLabel
只会在我的项目中崩溃。它在以下方法中崩溃:
- (NSArray *) links {
return [_linkModels valueForKey:@"result"];
}
LinkModels
变为NSZombie
。