简体   繁体   English

快速截断的 textView

[英]textView with truncation swift

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

If the text is not editable, use UILabel instead, which gives you this behavior out of the box.如果文本不可编辑,请改用 UILabel,它为您提供这种开箱即用的行为。

Otherwise you will have to build your own Text Kit stack and write your own NSLayoutManager to achieve this.否则,您将不得不构建自己的 Text Kit 堆栈并编写自己的 NSLayoutManager 来实现这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM