Return to Snippet

Revision: 26233
at April 21, 2010 08:34 by BenClayton

Initial Code
// resize description label to fit text..
			UIFont* font = descriptionLabel.font;			
			CGSize constraintSize = CGSizeMake(descriptionLabel.frame.size.width, MAXFLOAT);
			CGSize labelSize = [descriptionLabel.text sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
			descriptionLabel.frame = CGRectMake(descriptionLabel.frame.origin.x, descriptionLabel.frame.origin.y, descriptionLabel.frame.size.width, labelSize.height);

// if the label's in a UIScrollView, and the label is at the bottom, here's how
// to make it scroll correctly.
// make the size of the scroll view be the distance from the top to the bottom of the 
// description label.
			scrollView.contentSize = CGSizeMake(scrollView.contentSize.width, descriptionLabel.frame.origin.y + descriptionLabel.frame.size.height);

Initial URL

Initial Description

Initial Title
iPhone: Resize a UILabel to fit the text inside it

Initial Tags

Initial Language
Objective C