Forked from danielphillips/UILabel+dynamicSizeMe.h
Created
February 13, 2014 00:25
-
-
Save CoderXL/8967373 to your computer and use it in GitHub Desktop.
Revisions
-
Daniel Phillips revised this gist
Aug 10, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #import "UILabel+dynamicSizeMe.h" @implementation UILabel (dynamicSizeMe) -(float)resizeToFit{ float height = [self expectedHeight]; -
Daniel Phillips created this gist
Jun 2, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ @interface UILabel (dynamicSizeMe) -(float)resizeToFit; -(float)expectedHeight; @end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #import "UILabel+dynamicSizeMe.h" @interface UILabel (dynamicSizeMe) -(float)resizeToFit{ float height = [self expectedHeight]; CGRect newFrame = [self frame]; newFrame.size.height = height; [self setFrame:newFrame]; return newFrame.origin.y + newFrame.size.height; } -(float)expectedHeight{ [self setNumberOfLines:0]; [self setLineBreakMode:UILineBreakModeWordWrap]; CGSize maximumLabelSize = CGSizeMake(self.frame.size.width,9999); CGSize expectedLabelSize = [[self text] sizeWithFont:[self font] constrainedToSize:maximumLabelSize lineBreakMode:[self lineBreakMode]]; return expectedLabelSize.height; } @end