Skip to content

Commit

Permalink
SPTextField 'autoSize' fix
Browse files Browse the repository at this point in the history
  • Loading branch information
racarone committed Dec 5, 2015
1 parent d866848 commit cecd621
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sparrow/src/Classes/SPTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,22 @@ - (void)createRenderedContents
options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
}

if (self.isHorizontalAutoSize) {
textSize = [attributedText boundingRectWithSize:CGSizeMake(FLT_MAX, textSize.height)
options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
width = textSize.width;
}

if (self.isVerticalAutoSize) {
textSize = [attributedText boundingRectWithSize:CGSizeMake(textSize.width, FLT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
height = textSize.height;
}

// avoid invalid texture size
if (width < 1) width = 1.0;
if (height < 1) height = 1.0;

float xOffset = 0;
if (hAlign == SPHAlignCenter) xOffset = (width - textSize.width) / 2.0f;
else if (hAlign == SPHAlignRight) xOffset = width - textSize.width;
Expand Down

0 comments on commit cecd621

Please sign in to comment.