Skip to content

Commit

Permalink
bugfix for YYText
Browse files Browse the repository at this point in the history
  • Loading branch information
ibireme committed Jan 6, 2016
1 parent 01495f6 commit 94dea55
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions YYKit/Text/String/NSAttributedString+YYText.m
Original file line number Diff line number Diff line change
Expand Up @@ -551,20 +551,29 @@ + (NSMutableAttributedString *)attachmentStringWithContent:(id)content
switch (alignment) {
case YYTextVerticalAlignmentTop: {
delegate.ascent = font.ascender;
delegate.descent = attachmentSize.height + font.descender;
if (delegate.descent < 0) delegate.descent = 0;
delegate.descent = attachmentSize.height - font.ascender;
if (delegate.descent < 0) {
delegate.descent = 0;
delegate.ascent = attachmentSize.height;
}
} break;
case YYTextVerticalAlignmentCenter: {
CGFloat fontHeight = font.ascender - font.descender;
CGFloat yOffset = font.ascender - fontHeight * 0.5;
delegate.ascent = attachmentSize.height * 0.5 + yOffset;
delegate.descent = attachmentSize.height - delegate.ascent;
if (delegate.descent < 0) delegate.descent = 0;
if (delegate.descent < 0) {
delegate.descent = 0;
delegate.ascent = attachmentSize.height;
}
} break;
case YYTextVerticalAlignmentBottom: {
delegate.ascent = attachmentSize.height + font.descender;
delegate.descent = -font.descender;
if (delegate.ascent < 0) delegate.ascent = 0;
if (delegate.ascent < 0) {
delegate.ascent = 0;
delegate.descent = attachmentSize.height;
}
} break;
default: {
delegate.ascent = attachmentSize.height;
Expand Down

0 comments on commit 94dea55

Please sign in to comment.