Get last visible word in UITextView with maximumNumberOfLines != 0
我有一个最大行数为 3 的 UITextView:
textView.textContainer.maximumNumberOfLines = 3
文本超过3行,我希望最后一个可见的单词会更多。
例如:
对于字符串 :
This string is pretty long and we would like to be able to identify the last word visible so we can display”more” instead of the word found.
对于 3 行,显示的文本是:
This string is pretty long and we would like to be able to identify
我正在寻找的结果:
This string is pretty long and we would like to be able to more
UITextView 或文本容器中是否有任何 API 可以让我显示最后一个单词?
我建议您使用此链接上的 ilyapuchka ReadMoreTextView 库。这是实现这一目标的最简单方法,而且非常轻量级。
您可以使用 CocoaPods 安装它,只需在 podfile 中实现 pod ‘ReadMoreTextView’ 即可使用它:
1
2 3 4 5 6 7 |
let textView = ReadMoreTextView()
textView.text =“Lorem ipsum dolor …” textView.shouldTrim = true |
- 这样可行。很高兴阅读此库的作者创建的文章:ilya.puchka.me/custom-uitextview-in-swift。
来源:https://www.codenong.com/43884217/