2

I have a UILabel, the data for this label is populated via a database, and the text will contain multiple links, and i'm looking for a way to display these within a Label cleanly, i.e. not

  "Click here for more information http://stackoverflow.com" 

but

  "Check stack overflow for more information"

Is there any easy way to do this with Swift?

ScoopMatt
  • 79
  • 2
  • 7

2 Answers2

2

You would have to have some way of mapping between the URL and the display string. There easiest way you can do this (albeit somewhat quick and dirty), is just by using a dictionary.

See below:

let urlCounterparts = [
    "http://stackoverflow.com/":"Stack Overflow",
    "http://jacob-king.co.uk/": "Jacob King"
]

Then when setting the value for you label text you could do something like the following:

label.text = "Check" + urlCounterparts[url] + " for more information."

Of course the more OO focussed way of doing this would be to create some kind of object that links between the two strings, but there are many ways you could architect this and to be honest its down to personal preference.

Jacob King
  • 6,025
  • 4
  • 27
  • 45
0

You can use the following libraries :

  1. TTTAttributedLabel
  2. ActiveLabel.swift
Arasuvel
  • 2,971
  • 1
  • 25
  • 40
  • 1
    From what i can tell here, these dont allow for clean names, just detection for url, mentions and hashtags, is that correct? – ScoopMatt Nov 08 '16 at 09:08