0

How do I resize the text in my UITextView so that it doesn't cut off the text? I have a UITextView set at a specific height and I want the text in that UITextView to fit in that height. In a UITextField you have a adjustSizeToWidth, but not in UITextView

adit
  • 32,574
  • 72
  • 229
  • 373

1 Answers1

1
CGRect frame = textView.frame;
frame.size.height = textView.contentSize.height;
textView.frame = frame;

Source: https://stackoverflow.com/a/2487402/253008

EDIT:

You can use

-(CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size

to check the width of the text in the UITextView and then when it reaches your set width you can start lowering the font size

Community
  • 1
  • 1
shabbirv
  • 8,958
  • 4
  • 33
  • 34
  • I wanted the height to be fixed and the text to resize it's font. Not the other way around – adit Jul 02 '12 at 21:47
  • this is tedious as I'll have to try a font one by one – adit Jul 02 '12 at 22:09
  • well you'll have the font you started with, everytime you reach the constrained width just subtract your font size by 1. I'm sure that's pretty much how UITextField does it – shabbirv Jul 02 '12 at 22:14