1

I am using default UItableViewCell to display text. Now lable of that cell is set to multiline as

defaultCell.textLabel?.numberOfLines = 0

And I have multiple cells containting multiline text. And I want to add links in that text something like below

This is multiLine Text which will lead you to the StackOverFlow. And you will find something there.

I searched and found solutions like using UITextView instead if UILable etc.

But I want to do it with a UILable. Thanks for your help.

Umair Afzal
  • 4,947
  • 5
  • 25
  • 50
  • 1
    Possible duplicate: http://stackoverflow.com/questions/1256887/create-tap-able-links-in-the-nsattributedtext-of-a-uilabel – Randy Dec 22 '16 at 08:26
  • @Randy I do no think its a duplicate because: Most of the answers are in Objective-c and They are SubClassing UiLable. How would you use that with default cell ? – Umair Afzal Dec 22 '16 at 08:29
  • 1
    I would subclass `UITableViewCell` and set a custom `UILabel` as one of its subviews – Randy Dec 22 '16 at 08:30
  • 1
    Rather subclass `UITableViewCell ` and use `UITextView`, much easier – Tj3n Dec 22 '16 at 08:31
  • I do understand that that I cal create a custom cell and use a lable or UiTextField. But the question How to do that with default cell – Umair Afzal Dec 22 '16 at 08:34

2 Answers2

2

You should use UITextView and set Detection for Links:

textView.dataDetectorTypes = UIDataDetectorTypes.Link

Or if you need labels, then you can use some 3rd party solution like this: https://github.com/TTTAttributedLabel/TTTAttributedLabel https://github.com/null09264/FRHyperLabel

Sasha Kozachuk
  • 1,283
  • 3
  • 14
  • 21
0

I think that what you really want in terms of UX is a link being represented by the entire cell. You should simply implement tableView(_:didSelectRowAt:) and send the user to the destination there.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Thanks for your answer, But I do no want a link being represented by the entire cell. But just the a specific text in the lable of cell. – Umair Afzal Dec 22 '16 at 08:35