Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions ZCAnimatedLabel/ZCAnimatedLabel/ZCCoreTextLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down