17

I need to restrict number of lines in a UITextView to 2 and add ellipses to any overflowing text. How would I do that? For some implementation reasons I cannot use UILabel.

ChikabuZ
  • 10,031
  • 5
  • 63
  • 86
Suchi
  • 9,989
  • 23
  • 68
  • 112

1 Answers1

46

You can do that by setting the properties of the textContainer like so:

textView.textContainer.maximumNumberOfLines = 2
textView.textContainer.lineBreakMode = .byTruncatingTail
CristinaTheDev
  • 1,952
  • 2
  • 17
  • 25
Artal
  • 8,933
  • 2
  • 27
  • 30
  • 1
    If the size of the view is right textView.textContainer.lineBreakMode = .byTruncatingTail is enough. – Warpzit Feb 07 '20 at 10:00