Skip to content

Commit

Permalink
Update YYTextLine.m
Browse files Browse the repository at this point in the history
fix layout bugs while aligment is 'center'
  • Loading branch information
CodeSlaveZhang authored May 24, 2023
1 parent e0f69dc commit cd7641b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions YYText/Component/YYTextLine.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ - (void)setCTLine:(_Nonnull CTLineRef)CTLine {
CGPoint pos;
CTRunGetPositions(run, CFRangeMake(0, 1), &pos);
_firstGlyphPos = pos.x;
///case CTLineGetTypographicBounds does not fix trailing while the text aligment is 'center'
NSDictionary *attrs = (id)CTRunGetAttributes(run);
NSParagraphStyle *paraStyle = attrs[NSParagraphStyleAttributeName];
if (paraStyle.alignment == NSTextAlignmentCenter) {
//fix the trailing as same as the leading
_lineWidth += _position.x;
}
} else {
_firstGlyphPos = 0;
}
Expand Down

0 comments on commit cd7641b

Please sign in to comment.