我正在使用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
. _