user3755632 user3755632 - 1 year ago 426
Swift Question

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.

Answer Source

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"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download