Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode how to Autoshrink a UITextView?

I have a Text View box and I want that rectangle to stay the same size while the text inside autoshrinks to fit the box. The reason I need this is because the text is pulled from a plist and the strings are all different lengths. Labels have an Autoshrink feature which is exactly what I want, but I can't figure out a way even through code to get a Text View to do the same thing. Please help!

like image 342
robertfiorentino Avatar asked Oct 02 '12 01:10

robertfiorentino


1 Answers

UILabels can have more than one line of text. You just need to set the following:

label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0; // 0 = unlimited number of lines, set to another number to have that as maximum

I'm not entirely sure if this works, but you can then combine this with label.adjustsFontSizeToFitWidth = YES; to have a multi-line label that autoshrinks text.

like image 85
neilvillareal Avatar answered Sep 21 '22 06:09

neilvillareal