How to make URL/Phone-clickable UILabel?

uilabel clickable link swift 4
uilabel clickable link swift github
uilabel hyperlink swift
uilabel clickable link objective-c
uilabel link color
nslinkattributename uilabel
shouldinteractwithurl uilabel
swift make attributed string clickable

I want to create a clickable label on my app leading me to a Safari webpage. I also want the user to be able to phone the numbers only by clicking on them ?

Thanks for your advices

You can use a UITextView and select Detection for Links, Phone Numbers and other things in the inspector.

Clickable link on a Swift label or TextView - The Startup, It seems easy to create a link on a label in a Swift iOS App. It… Chinese, yet does not reveal the webpage URL that the link would lead us to. on a UILabel or a UITextview, how can we make the link clickable in the same  How to create clickable phone number. Ask Question Asked 9 years, 10 months ago. Active 7 years, 1 month ago. How to make URL/Phone-clickable UILabel?

Use UITextView instead of UILabel and it has a property to convert your text to hyperlink.

yourTextView.editable = NO;
yourTextView.dataDetectorTypes = UIDataDetectorTypeAll;
yourTextView.editable = false; 
yourTextView.dataDetectorTypes = UIDataDetectorTypes.All;

This will detect links automatically.

See the documentation for details.

How to Create Multiple Tappable Links in a UILabel, A good example is a UILabel that looks like the following below the Facebook button. There are 2 tasks at hand - first using NSAttributedString  I want to create label in iOS, can anyone help me to make the first word of the label's text bold and clickable. The label displays username and its comment and the first word is always the username.

That's definitely what you need. You can also apply attributes for your label, like underline, and apply different colors to it. Just check the instructions for clickable urls.

Mainly, you do something like the following:

NSRange range = [label.text rangeOfString:@"me"];
[label addLinkToURL:[NSURL URLWithString:@""] withRange:range]; // Embedding a custom link in a substring

michaelloistl/ContextLabel: A simple to use drop in , A simple to use drop in replacement for UILabel written in Swift that provides of links such as URLs, phone numbers, twitter style usernames and hashtags. ContextLabel doesn't have any special dependencies so just include the files  By adding UITapGestureRecognizer to the label, to make UIlabel clickable. Before adding the label to tapgesture, don't forgot to enable userinteraction for UIlabel Here is the sample code:

You can make custom UIButton and setText what ever u want and add method with that.

    UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [sampleButton setFrame:CGRectMake(kLeftMargin, 10, self.view.bounds.size.width - kLeftMargin - kRightMargin, 52)];
    [sampleButton setTitle:@"URL Text" forState:UIControlStateNormal];
    [sampleButton setFont:[UIFont boldSystemFontOfSize:20]];

    [sampleButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:sampleButton];

 // open url


TTTAttributedLabel/TTTAttributedLabel: A drop-in , A drop-in replacement for UILabel that supports attributes, data detectors, links, and manually by specifying a range for a URL, address, phone number, event,  Drag drop UILabel in your Storyboard and define custom class name to FRHyperLabel in identify inspector as shown in image. Connect your UILabel from storyboard to your viewController.h file; @property (weak, nonatomic) IBOutlet FRHyperLabel *label; Now in your viewController.m file add following code.

If you want this to be handled by UILabel and not UITextView, you can make UILabel subclass, like this one:

class LinkedLabel: UILabel {

fileprivate let layoutManager = NSLayoutManager()
fileprivate let textContainer = NSTextContainer(size:
fileprivate var textStorage: NSTextStorage?

override init(frame aRect:CGRect){
    super.init(frame: aRect)

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

func initialize(){

    let tap = UITapGestureRecognizer(target: self, action: #selector(LinkedLabel.handleTapOnLabel))
    self.isUserInteractionEnabled = true

override var attributedText: NSAttributedString?{
        if let _attributedText = attributedText{
            self.textStorage = NSTextStorage(attributedString: _attributedText)


            self.textContainer.lineFragmentPadding = 0.0;
            self.textContainer.lineBreakMode = self.lineBreakMode;
            self.textContainer.maximumNumberOfLines = self.numberOfLines;


func handleTapOnLabel(tapGesture:UITapGestureRecognizer){

    let locationOfTouchInLabel = tapGesture.location(in: tapGesture.view)
    let labelSize = tapGesture.view?.bounds.size
    let textBoundingBox = self.layoutManager.usedRect(for: self.textContainer)
    let textContainerOffset = CGPoint(x: ((labelSize?.width)! - textBoundingBox.size.width) * 0.5 - textBoundingBox.origin.x, y: ((labelSize?.height)! - textBoundingBox.size.height) * 0.5 - textBoundingBox.origin.y)

    let locationOfTouchInTextContainer = CGPoint(x: locationOfTouchInLabel.x - textContainerOffset.x, y: locationOfTouchInLabel.y - textContainerOffset.y)
    let indexOfCharacter = self.layoutManager.characterIndex(for: locationOfTouchInTextContainer, in: self.textContainer, fractionOfDistanceBetweenInsertionPoints: nil)

    self.attributedText?.enumerateAttribute(NSLinkAttributeName, in: NSMakeRange(0, (self.attributedText?.length)!), options: NSAttributedString.EnumerationOptions(rawValue: UInt(0)), using:{
        (attrs: Any?, range: NSRange, stop: UnsafeMutablePointer<ObjCBool>) in

        if NSLocationInRange(indexOfCharacter, range){
            if let _attrs = attrs{

                UIApplication.shared.openURL(URL(string: _attrs as! String)!)


This class was made by reusing code from this answer. In order to make attributed strings check out this answer. And here you can find how to make phone urls.

Hyperlink Label, Make a hyperlink label in iOS with Swift. Make sure the text you need to make clickable is exacly same to the full text. let termLabel = UILabel() let formattedText = String.format(strings: [term, policy], boldFont: UIFont. I would like to make a UILabel clickable. I have tried this, but it doesn't work: class DetailViewController: UIViewController { @IBOutlet weak var tripDetails: UILabel! override func

How to make tappable links in NSAttributedString, How to make tappable links in NSAttributedString Click here to visit our frequently asked questions about HTML5 video. attributedText = attributedString } func textView(_ textView: UITextView, shouldInteractWith URL: URL, Xcode, Instruments, Cocoa Touch, Touch ID, AirDrop, iBeacon, iPhone, iPad,  How to make URL/Phone-clickable UILabel? (6) I want to create a clickable label on my app leading me to a Safari webpage. I also want the user to be able to phone the numbers only by clicking on them ? Thanks for your advices

iOS, The key to create a clickable UILabel is to enable user interaction. Swift#. let label = UILabel() label.userInteractionEnabled = true let gesture =  « first day (215 days earlier) ← previous day next day → last day (1034 days later) »

Easiest way to make a label a clickable Hyperlink? : iOSProgramming, If you want to have text instead of the url then you will need a uiwewebview. There are fancy things you can do with uilabel but I recomend using the methods​ 

  • Possible duplicate of Create tap-able "links" in the NSAttributedText of a UILabel?
  • I have a self resizing label which can accommodate N lines of text. How can I make the links in this label clickable without implementing UITextView.
  • @bibscy then you can use the NSAttributedText. Look at…
  • this colors the link blue and underlines it, but does seem to make it clickable, at least on iOS 7.
  • Swift code: yourTextView.editable = false; yourTextView.dataDetectorTypes = UIDataDetectorTypes.All;
  • @SameeraChathuranga Thank you for this!
  • the question is about UILabel, not UITextView.
  • This saved a lot of time. Thank you so much!
  • It is magnificent, thank you! Much better than using a UITextView in several ways.
  • Using Swift: let range = (label.text as NSString).rangeOfString("me")
  • Setting the font is now done by: button.titleLabel.font = [UIFont systemFontOfSize:size];
  • perfect. just what i was looking for! i've been waiting on you to post your answer.
  • the question how to use in UILabel, rather than TextViews. thanks.