textView with truncation swift

2.5k views Asked by At

I have a text view with a set height on a table view. As the content of my text view is greater than what fits in the set height, the content is truncated.

That is fine, but my issue is that I would like the text view to contain the first few lines of the content and then have the ... but instead the first few lines are missing and the text view is displaying the last few lines of the content passed in.

I can't find any examples on how to implement this.

I have tried the following but to no avail:

descriptionLabel.textContainer.lineBreakMode = NSLineBreakMode.ByWordWrapping
1

There are 1 answers

4
matt On BEST ANSWER

If the text is not editable, use UILabel instead, which gives you this behavior out of the box.

Otherwise you will have to build your own Text Kit stack and write your own NSLayoutManager to achieve this.