0

I have a problem. I would like to know how I can get the exact number of WRITTEN lines of a text in a text view . I do not want the number of lines possible, but those that have been used and filled by characters.

For example:

In this case the result is 2. In this case the result is 3.

mrcf
  • 149
  • 2
  • 9

1 Answers1

0

you could try going something along the lines of

[textField sizeToFit]; //Get the minimum height and width for the text
NSInteger numLines = textField.frame.size.height / textField.font.lineHieght

However I haven't tried it myself

bencunningham
  • 356
  • 1
  • 5
  • 12
  • You might find this is not entirely accurate when a larger number of lines is involved. In particular you could have problems on an iPhone 6+ - see http://stackoverflow.com/a/2487402/189804 - sizeToFit appears to work differently! – Adam Eberbach Apr 10 '15 at 00:29