Skip to content

Instantly share code, notes, and snippets.

@maninp
Last active August 29, 2015 14:24
Show Gist options
  • Save maninp/514b695fd2a34015de43 to your computer and use it in GitHub Desktop.
Save maninp/514b695fd2a34015de43 to your computer and use it in GitHub Desktop.
- (CGRect)getMaxFrameForText:(UILabel *)label {
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
CGRect currentFrame = label.frame;
CGSize max = CGSizeMake(label.frame.size.width, 250);
CGRect textRect = [label.text boundingRectWithSize:max options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:nil];
currentFrame.size.height = ceilf(textRect.size.height);
return currentFrame;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment