6

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!

2
  • Why do you need UITextView? Why can't you use UILabel?
    – Nekto
    Oct 2, 2012 at 1:32
  • UILabels are only one line, centered in the middle. When I loaded the text from the NSDictionary it shrinks the text to tiny font and then adds a "..." at the end but the text is still only one line. I want the text to fill the entire box (about the whole size of the screen). Oct 2, 2012 at 2:04

1 Answer 1

2

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.

2
  • 2
    This worked, thanks. A nice workaround but I wish I could do it in Text View. Oct 2, 2012 at 3:18
  • 1
    The line breaks work but adjustsFontSizeToFitWidth doesn't work with multiple lined labels. Oct 4, 2012 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.