Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest way to implement a "Read More" button to expand a UITextView in iOS Swift 2?

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.

like image 265
user3755632 Avatar asked Jul 07 '16 11:07

user3755632


1 Answers

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.

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"
like image 127
Tarvo Mäesepp Avatar answered Nov 14 '22 22:11

Tarvo Mäesepp