Note that there are some explanatory texts on larger screens.

plurals
  1. POString length with given font to fit UITextView
    primarykey
    data
    text
    <p>I need to move text that the user has entered into a large multi-line <code>UITextView</code> into a smaller (but still multi-line) <code>UITextView</code>*. If the user has entered more text than will display in the smaller view, I want to truncate the text so that it fits with all the (truncated) text visible. (Neither the large <code>UITextView</code> nor the smaller one should scroll.)</p> <p>What's the best way to do this?</p> <p>I can use a loop, shortening the string by a character each time, and then use <code>NSString</code>'s <code>sizeWithFont: constrainedToSize: lineBreakMode:</code> to find out the height this shorter string would need, and then compare that against the height I have available in my smaller <code>UITextView</code>, ending the loop when the string will fit - but that seems slow and awkward. There must be a better way.</p> <p>I'd like to just tell the destination <code>UITextView</code> to truncate its displayText member as it displays it on screen, but I've not been able to find a way to do that. </p> <p>*More context on this, from a comment I made below: </p> <p>I've got a landscape app. I change the layout of the view depending on the photo the user chooses. If it's a landscape photo, the caption is smaller - just a line at the bottom of the photo. If she chooses a portrait photo, then there's plenty of space I can use for the caption at the side of the photo, so the caption is bigger.</p> <p>If the user changes her photo orientation from portrait to landscape, then I want to truncate the text and then allow her to edit it so that it makes sense. I could just zap it, but I'd prefer to preserve it to minimize her typing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload