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
Asked
Active
Viewed 825 times
0
-
as far as i know UITextView is a scrollable View, so why would you want to squeeze your text in a specific height when you can just scroll through the text? – robustus Jul 02 '12 at 21:12
-
then UITextView isn't what you want... – robustus Jul 03 '12 at 08:44
1 Answers
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
-
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
-
-
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