From 97fcb8e34b68034e6f4f1c1730b3e89c506f1d59 Mon Sep 17 00:00:00 2001 From: kamendo Date: Fri, 5 Jan 2018 12:18:02 +0200 Subject: [PATCH] crash if a label contains '\n' 'NSInvalidArgumentException', reason: '*** -[NSLayoutManager glyphRangeForTextContainer:]: given container does not appear in the list of containers for this NSLayoutManager.' --- TSLabel/TSLabel.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/TSLabel/TSLabel.m b/TSLabel/TSLabel.m index c0d1c54..743daf4 100644 --- a/TSLabel/TSLabel.m +++ b/TSLabel/TSLabel.m @@ -54,6 +54,10 @@ - (void) layoutManager: (NSLayoutManager *) layoutManager didCompleteLayoutForTe if ( label != nil && [label isKindOfClass: [TSLabel class]] ) { + //this happens if label clips part of the content (NSInvalidArgumentException) + if([layoutManager.textContainers indexOfObject:textContainer] == NSNotFound ) + layoutManager = textContainer.layoutManager; + CGRect containerGlyphBounds = [layoutManager boundingRectForGlyphRange: [layoutManager glyphRangeForTextContainer: textContainer] inTextContainer: textContainer]; // determine the bounds of each link and record that information with the TSLabel @@ -239,4 +243,4 @@ - (void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event [self setAttributedText: self.attributedText]; } -@end \ No newline at end of file +@end