iosobjective-cuitextviewsizetofit

sizeThatFits sometimes returns a height that is one line more (or less) than my text in iOS 8


I try to get the fitting height for a UITextView with this code:

[textView sizeThatFits:CGSizeMake(textView.frame.size.width, FLT_MAX)].height;

It returns the correct value most of the time, but sometimes it returns a value that is one line more or less than the correct height value.

Here is an example when it is correct:

correct height value

...and here is another when it's wrong (the full text is "California (There Is No End to Love)")

incorrect height value

How can I fix this?


Solution

  • Using a UILabel instead of a UITextView solved my problem.