-1

Possible Duplicate:
How do I size a UITextView to its content?

i have a textview called labelTextView i want to set the size of the UITextView dynamically so that according to text in the UITextView the size gets adjusted . i wanted to know how to create it ,any help would be helpful .since i am creating it dynamically i dont need to insert textview in the nib file .

Community
  • 1
  • 1
raptor85
  • 125
  • 2
  • 4
  • 12
  • Common, a simple search with your title found several answers to that question already! – jv42 Nov 09 '11 at 17:03

1 Answers1

-1

You can use the NSString sizeWithFont: methods to determine the size.

CGRect textViewFrame = textView.frame;
CGSize constrainedSize = CGSizeMake(textViewFrame.size.width, CGFLOAT_MAX);
CGSize textSize = [text sizeWithFont:textView.font constrainedToSize:constrainedSize];
CGRect newTextViewFrame = CGRectMake(textViewFrame.origin.x, textViewFrame.origin.y, textViewFrame.size.width, textSize.height);
textView.frame = newTextViewFrame;
jaminguy
  • 25,840
  • 2
  • 23
  • 21