Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

Commit

Permalink
- textRectForBounds… now correctly returns the y offset and text size…
Browse files Browse the repository at this point in the history
… height
  • Loading branch information
jasongregori committed Apr 23, 2012
1 parent 7c5dea5 commit f2b227f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions TTTAttributedLabel.m
Expand Up @@ -606,20 +606,19 @@ - (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)num

if (textSize.height < textRect.size.height) {
CGFloat yOffset = 0.0f;
CGFloat heightChange = (textRect.size.height - textSize.height);
switch (self.verticalAlignment) {
case TTTAttributedLabelVerticalAlignmentTop:
heightChange = 0.0f;
break;
case TTTAttributedLabelVerticalAlignmentCenter:
yOffset = floorf((textRect.size.height - textSize.height) / 2.0f);
break;
case TTTAttributedLabelVerticalAlignmentBottom:
yOffset = textRect.size.height - textSize.height;
break;
}

textRect.origin.y += yOffset;
textRect.size.height -= heightChange - yOffset;
textRect.size.height = textSize.height;
}

return textRect;
Expand Down Expand Up @@ -658,6 +657,9 @@ - (void)drawTextInRect:(CGRect)rect {
// First, get the text rect (which takes vertical centering into account)
CGRect textRect = [self textRectForBounds:rect limitedToNumberOfLines:self.numberOfLines];

// CoreText draws it's text aligned to the bottom, so we move the CTM here to take our vertical offsets into account
CGContextTranslateCTM(c, 0.0f, rect.size.height - textRect.origin.y - textRect.size.height);

// Second, trace the shadow before the actual text, if we have one
if (self.shadowColor && !self.highlighted) {
CGContextSetShadowWithColor(c, self.shadowOffset, self.shadowRadius, [self.shadowColor CGColor]);
Expand Down

0 comments on commit f2b227f

Please sign in to comment.