-1

I'm trying to create an expandable label that looks like the one in the picture: enter image description here

I have two problems:

  1. How do I make the label truncate the tail such that it leaves enough place for the More button/clickable text?
  2. How do I place the More text?

Maybe, I am going about it the wrong way? Instead of playing with the number of lines, should I maybe try to calculate how much text goes into one and a half line and present it only, and then when clicking More I present the whole text?

Would appreciate any advice, thanks!

Yotam
  • 9,789
  • 13
  • 47
  • 68

1 Answers1

3

You can use this library to achieve your expected output.

https://github.com/apploft/ExpandableLabel

Specify the number of lines you want to display default.

expandableLabel.numberOfLines = 2

Set true if the label should be collapsed or false for expanded.

expandableLabel.collapsed = true

collapsedAttributedLink Set the link name that is shown when collapsed.

expandableLabel.collapsedAttributedLink = NSAttributedString(string: "More")

expandedAttributedLink Set the link name that is shown when expanded. It is optional and can be nil.

expandableLabel.expandedAttributedLink = NSAttributedString(string: "Less")
AtulParmar
  • 4,358
  • 1
  • 24
  • 45