Make Clickable UILabel Using Swift

Solutions Collect From Internet About “Make Clickable UILabel Using Swift”

You can not do with the simple label.

There is library available in the github.

https://github.com/TTTAttributedLabel/TTTAttributedLabel

From this you can use the method called yourLabel.addLinkToURL()

class ViewController: UIViewController , TTTAttributedLabelDelegate{

    @IBOutlet var lbl: TTTAttributedLabel!
    override func viewDidLoad() {
        super.viewDidLoad()

        var str : NSString = "Hello this is link"
        lbl.delegate = self
        lbl.text = str as String
        var range : NSRange = str.rangeOfString("link")
        lbl.addLinkToURL(NSURL(string: "http://github.com/mattt/")!, withRange: range)
    }

    func attributedLabel(label: TTTAttributedLabel!, didSelectLinkWithURL url: NSURL!) {
        UIApplication.sharedApplication().openURL(url)
    }
}

enter image description here