2

I want to show some text + URL +some text + URL + some text. After creating this string with text + URL I want to set this text to a UILabel. How can is achieve this? I can use some other control instead of UILabel to show the text on the view I am flexible with that. I have googled for this but I found only one way which is to use the attributed text and the tap recognizer to recognize the touches and then handle them accordingly.Which I think will complicate things in my case. I want to know if there any way around to deal with this.

I want to do something like this "If you want to create a account go to Google.com or watch the demo video.You can email us call support 444-1520-1458"

All the text that is there in bold I want that to be clickable. And on that click I want to perform some action.I also want that bold text to appear in blue. I have googled for this issue found some links: 1)iOS UITextView or UILabel with clickable links to actions

2)How to make a clickable link in an NSAttributedString for a

In case of first link the logic seems perfect but the text I enter not center aligned. In second case the Attributed string in not ckickable. I have searched but havnt got success.Need some help

Community
  • 1
  • 1
Nikhil
  • 379
  • 1
  • 3
  • 14
  • 1
    It's not clear what you're asking for. In your example, do you want the label text to read something like: text http://url1.com some text http://url2.com some text, or do you want the output from calling these urls to be inserted into your text string (and the urls to be tappable)? Or do these urls provide graphics that you want to separate your text? – Owen Hartnett Aug 03 '16 at 15:09
  • I want the urls to be inserted into my text string and want to assign that string to a label. – Nikhil Aug 04 '16 at 06:01
  • Duplicate of: http://stackoverflow.com/questions/10681965/how-to-make-url-phone-clickable-uilabel – Owen Hartnett Aug 04 '16 at 13:31
  • use https://github.com/Krelborn/KILabel – Mahesh Agrawal Aug 05 '16 at 09:19

1 Answers1

0

When I had to work with hyperlinks I did this

I set the text to a UITextView

let link = "<a href=\"\(link)\">Link</a>" 

let aLink = try! NSMutableAttributedString(data: link.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)

self.textView.attributedText = aLink

This worked for me

Brett Ponder
  • 145
  • 1
  • 8