From b29a9f43fd053a5d2b24bde7ce4503024fbdac41 Mon Sep 17 00:00:00 2001 From: viktor calonia Date: Wed, 26 Aug 2015 00:28:18 +0800 Subject: [PATCH 1/2] Fix hiding of characters when using other font --- ZCAnimatedLabel/ZCAnimatedLabel/ZCCoreTextLayout.m | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ZCAnimatedLabel/ZCAnimatedLabel/ZCCoreTextLayout.m b/ZCAnimatedLabel/ZCAnimatedLabel/ZCCoreTextLayout.m index 96b3ff3..fc62ca0 100644 --- a/ZCAnimatedLabel/ZCAnimatedLabel/ZCCoreTextLayout.m +++ b/ZCAnimatedLabel/ZCAnimatedLabel/ZCCoreTextLayout.m @@ -193,20 +193,14 @@ - (void) layoutWithAttributedString: (NSAttributedString *) attributedString con textBlock.textRange = enclosingRange; NSMutableAttributedString *subLineString = [[attributedString attributedSubstringFromRange:NSMakeRange(enclosingRange.location + lineRange.location, enclosingRange.length)] mutableCopy]; [subLineString removeAttribute:NSParagraphStyleAttributeName range:NSMakeRange(0, subLineString.length)]; - UIFont *font = [subLineString attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL]; [textBlock updateBaseAttributedString:subLineString]; CGFloat startOffset = CTLineGetOffsetForStringIndex(line, enclosingRange.location + lineRange.location, NULL); CGFloat endOffset = CTLineGetOffsetForStringIndex(line, enclosingRange.location + enclosingRange.length + lineRange.location, NULL); - CGFloat realHeight = font.xHeight + font.ascender + font.descender; - CGFloat absAscender = font.descender > 0 ? font.descender : -font.descender; - CGFloat originDiff = (maxCharHeight - realHeight) - (maxDescender - absAscender); + CGFloat realHeight = lineHeight; + CGFloat originDiff = 0; - if (self.groupType == ZCLayoutGroupLine) { - realHeight = lineHeight; - originDiff = 0; - } textBlock.charRect = CGRectMake(startOffset + lineOrigins[i].x, startOffsetY + originDiff, endOffset - startOffset, realHeight); [textAttributes addObject:textBlock]; From 4939bf52f1e5678fcedd95f5b1c43571730c1ef4 Mon Sep 17 00:00:00 2001 From: viktor calonia Date: Fri, 28 Aug 2015 09:41:28 +0800 Subject: [PATCH 2/2] Layout animated label every lay outing --- ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.m b/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.m index b67045f..cbbb08b 100644 --- a/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.m +++ b/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.m @@ -143,6 +143,12 @@ - (void) _removeAllTextLayers #pragma mark layout related +- (void)layoutSubviews { + [super layoutSubviews]; + + [self _layoutForChangedString]; +} + - (void) sizeToFit { self.frame = CGRectMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame), CGRectGetWidth(self.frame), self.layoutTool.estimatedHeight);