实现“阅读更多”的最简单方法按钮在iOS Swift 2中展开UITextView?

问题描述:

我希望实现一个Read more按钮,它将扩展UITextView,以便有人可以根据需要阅读整个文本。我还没有找到一种简单的方法来实现这一目标。我试着用容器的高度玩,但它没有给我想要的结果。我真的很感激任何想法。

I am looking to implement a "Read more" button that will expand the UITextView so that someone can read the whole text if they wish. I haven't managed to find an easy way to achieve this yet. I tried to "play" with the container's height but it doesn't give me the desired results. I would really appreciate any ideas.

我建议你使用ilyapuchka ReadMoreTextView 链接。这是实现这一目标的最简单方法,它是轻量级的。

I would suggest you the ilyapuchka ReadMoreTextView library which is on this link. It is the easiest way to achieve this and it is retty lightweight.

您可以使用CocoaPods安装它,只需实现 pod'ReadMoreTextView'进入podfile,您可以使用它:

You can install it with CocoaPods, just implement pod 'ReadMoreTextView' into the podfile and you can use it likie this:

let textView = ReadMoreTextView()

textView.text = "Lorem ipsum dolor ..."

textView.shouldTrim = true
textView.maximumNumberOfLines = 3
textView.trimText = "Read more"