I have a description of myObject and i show it in UILabel. I want to add 'More' button to my UILabel
if a description is too long. On Github i have found TTTAttributedLabel which allows to use hyperlinks. The question is, is there some special features in UILabel
or UITextView
to resolve my issue or i have to use TTTAttributedLabel
?

- 3,569
- 4
- 34
- 51
3 Answers
The best option is certainly to use TTTAttributedLabel
.
UILabel
and UITextView
are designed simply for showing static text. There is no method for adding tappable elements.
As an alternative, before I leaned of TTTAttributedLabel
I simply placed a UIButton
with a custom style over my UILabel
. The button was invisible but still responded to taps. This works best for static text though, as the button needs to be placed correctly on the interface to cover the correct part of the text.

- 2,696
- 4
- 23
- 46
-
hi c.cam108 i have used TTTAttributedLabel and when i set the [label setTruncationTokenString:@"... MORE"]; its not showing on label.What should be the problem? – BhavikKama Feb 19 '14 at 09:09
-
@BhavikKama did you manage to get More on your string. I'm struggling to get it. Can you help me? – Rushi May 09 '14 at 05:12
-
Sorry, I have never used `TTTAttribtedLabel` in that way - I would manually truncate the string and create the "MORE" text with a hyperlink that would then allow me to manually change the displayed text. – colincameron May 19 '14 at 11:25
With TTTAtributtedLabel
is pretty easy to add a "MORE" text at the end.
You have truncationTokenString
and truncationTokenStringAttributes
. Super easy!
Example:
[label setTruncationTokenString:@"... MORE"];
https://github.com/mattt/TTTAttributedLabel
Documentation: http://cocoadocs.org/docsets/TTTAttributedLabel/1.8.0/Classes/TTTAttributedLabel.html#//api/name/truncationTokenString
In my case I don't need anything more because I just change the numberOfLines
when the cell is selected to make it grow.

- 1,623
- 17
- 16
You can try the 3rd library ExpandableLable written by Swift.
Set the custom class of your UILabel to ExpandableLabel and set the desired number of lines and collapsed text:
expandableLabel.numberOfLines = 5
expandableLabel.collapsedAttributedLink = NSAttributedString(string: "more")
expandableLabel.ellipsis = NSAttributedString(string: "...")
// update label expand or collapse state
expandableLabel.collapsed = true
You may need set a delegate
to get notified in case the link has been touched.

- 801
- 10
- 13
-
Do you have any ideas on see less? http://stackoverflow.com/questions/41853362/see-less-in-expandablelabel-ios – AMAN77 Jan 26 '17 at 08:13