This question has been asked numerous times, but the two or three answers repeatedly given don't seem to work.
The issue is: A `UITextView that contains some arbitrary text. After some action, the UITextView needs to resize both horizontally and vertically to snugly fit the text.
Answers on other questions give values which appear to be about the same width/height of the text; however, when the UITextView
is resized to the calculated size, it's not quite right and the text line-breaks differently than it did originally.
Suggested methods include using – sizeWithFont:constrainedToSize:
and other NSString methods, sizeThatFits:
method of the UITextView (this gives a more correct height, but the full width of the view), and the contentSize
property of the text view (also gives the wrong width).
Is there an accurate way to determine the width of a UITextView
's text? or is there some hidden padding in the text view that makes the actually width the text fits in smaller? Or something else I'm completely missing?