Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Adjust UILabel to change it's frame according to it's content
@interface UILabel (dynamicSizeMe)
#import "UILabel+dynamicSizeMe.h"
@implementation UILabel (dynamicSizeMe)
float height = [self expectedHeight];
CGRect newFrame = [self frame];
newFrame.size.height = height;
[self setFrame:newFrame];
return newFrame.origin.y + newFrame.size.height;
[self setNumberOfLines:0];
[self setLineBreakMode:UILineBreakModeWordWrap];
CGSize maximumLabelSize = CGSizeMake(self.frame.size.width,9999);
CGSize expectedLabelSize = [[self text] sizeWithFont:[self font]
lineBreakMode:[self lineBreakMode]];
return expectedLabelSize.height;
Copy link

i only wanted to know the size of the label reduces according to the data but it is alwaz in single line....max 45 charc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment