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); 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];