Created
November 27, 2012 06:43
-
-
Save Lejdborg/4152775 to your computer and use it in GitHub Desktop.
- [UILabel resizeToFit:]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Resizes a UILabel to be exactly the size it needs to be to fit it's contents | |
* within the constraints of CGSize. | |
* | |
* @param maxSize The maximum allowable size the label may fit in | |
*/ | |
- (void)resizeToFit:(CGSize)maxSize { | |
CGSize expectedLabelSize = [[self text] sizeWithFont:[self font] | |
constrainedToSize:maxSize | |
lineBreakMode:[self lineBreakMode]]; | |
CGRect newFrame = [self frame]; | |
newFrame.size = expectedLabelSize; | |
[self setFrame:newFrame]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment