Make link in UILabel.attributedText *not* blue and *not* underlined

I want some words within my OHAttributedLabel to be links, but I want them to be colors other than blue and I don’t want the underline.

This is giving me a blue link with underlined text:

  • Xcode 5/6: View Debugging always grayed out?
  • What exactly does delegate do in xcode ios project?
  • Entitlements file do not match those specified in your provisioning profile.(0xE8008016)
  • Automatic @property synthesize not working on NSManagedObject subclass
  • Objects Sorting With date ,Time Problem in Array(Iphone Development)
  • CMake link_directories from library
  •  -(void)createLinkFromWord:(NSString*)word withColor:(UIColor*)color atRange:(NSRange)range{
        NSMutableAttributedString* mutableAttributedText = [self.label.attributedText mutableCopy];   
        [mutableAttributedText beginEditing];
        [mutableAttributedText addAttribute:kOHLinkAttributeName
                       value:[NSURL URLWithString:@""]
        [mutableAttributedText addAttribute:(id)kCTForegroundColorAttributeName
        [mutableAttributedText addAttribute:(id)kCTUnderlineStyleAttributeName
                       value:[NSNumber numberWithInt:kCTUnderlineStyleNone]
        [mutableAttributedText endEditing];
        self.label.attributedText = mutableAttributedText;

    Since I’m using OHAttributedLabel, I also tried using the methods in it’s NSAttributedString+Attributes.h category, but those return blue underlined links as well:

    -(void)createLinkFromWord:(NSString*)word withColor:(UIColor*)color atRange:(NSRange)range{
    NSMutableAttributedString* mutableAttributedText = [self.label.attributedText mutableCopy];
    [mutableAttributedText setLink:[NSURL URLWithString:@""] range:range];
    [mutableAttributedText setTextColor:color range:range];
    [mutableAttributedText setTextUnderlineStyle:kCTUnderlineStyleNone range:range];
    self.label.attributedText = mutableAttributedText;

    If I comment out the line setting the links in each version, the text gets colored to what I pass in – that works. It just seems like setting the link is overriding this and turning it back to blue.

    Unfortunately the apple docs page I found shows how to set the link text to blue and underline it, exactly what I don’t need:

    9 Solutions Collect From Internet About “Make link in UILabel.attributedText *not* blue and *not* underlined”

    So I ended up using TTTAttributedLabel:

    -(void)createLinkFromWord:(NSString*)word withColor:(UIColor*)color atRange:(NSRange)range{
        NSMutableAttributedString* newTextWithLinks = [self.label.attributedText mutableCopy];
        NSURL *url = [NSURL URLWithString:@""];
        self.label.linkAttributes = @{NSForegroundColorAttributeName: color, 
                                       NSUnderlineStyleAttributeName: @(NSUnderlineStyleNone)};
        [self.label addLinkToURL:url withRange:range];

    I found that OHAttributedLabel actually does have methods to set links and declare colors and underline styles for those links. However, I wanted the links to be different colors based on a parameter. TTTAttributedLabel allows this by letting you set it’s linkAttributes property for each link you create.

    I am using TTTAttributedLabel. I wanted to change the color of the linked text, and keep it underlined. Pim’s answer looked great, but didn’t work for me. Here’s what did work:

    label.linkAttributes = @{ (id)kCTForegroundColorAttributeName: [UIColor magentaColor],
                               (id)kCTUnderlineStyleAttributeName : [NSNumber numberWithInt:NSUnderlineStyleSingle] };

    Note: if you don’t want the text underlined, then remove the kCTUnderlineStyleAttributeName key from the dictionary.

    Here’s is my improved version of Ramsel’s already great answer.
    I believe it’s much more readable, and I hope it will come to good use.

    label.linkAttributes = @{ NSForegroundColorAttributeName: [UIColor whiteColor],
                              NSUnderlineStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle] };

    Here’s a list of other attibute names.

    If you are using a uitextview, you might have to change the tintColor to change the link color

    Swift 2.3 example for TTTAttributedLabel:

    yourLabel.linkAttributes       = [
        NSForegroundColorAttributeName: UIColor.grayColor(),
        NSUnderlineStyleAttributeName: NSNumber(bool: true)
    yourLabel.activeLinkAttributes = [
        NSForegroundColorAttributeName: UIColor.grayColor().colorWithAlphaComponent(0.8),
        NSUnderlineStyleAttributeName: NSNumber(bool: false)

    Swift 3 example for TTTAttributedLabel:

    yourLabel.linkAttributes = [
        NSUnderlineStyleAttributeName: NSNumber(value: NSUnderlineStyle.styleNone.rawValue)
    yourLabel.activeLinkAttributes = [
        NSUnderlineStyleAttributeName: NSNumber(value: NSUnderlineStyle.styleDouble.rawValue)

    For Swift 3 using TTTAttributedLabel

    let title: NSString = "Fork me on GitHub!"
    var attirutedDictionary = NSMutableDictionary(dictionary:attributedLabel.linkAttributes)
    attirutedDictionary[NSForegroundColorAttributeName] =
    attirutedDictionary[NSUnderlineStyleAttributeName] =  NSNumber(value: NSUnderlineStyle.styleNone.rawValue)
    attributedLabel.attributedText = NSAttributedString(string: title as String)
    attributedLabel.linkAttributes = attirutedDictionary as! [AnyHashable: Any]
    let range = subtitleTitle.range(of: "me")
    let url = URL(string: "")
    attributedLabel.addLink(to: url, with: range)

    For Swift 3 following way worked out for me using TTTAttributedLabel:

    1) Add a label on the storyboard and define its class to be TTTAttributedLabel
    Storyboard view

    2) In code define
    @IBOutlet var termsLabel: TTTAttributedLabel!

    3) Then in ViewDidLoad write these lines

    let textString = "By using this app you agree to the Privacy Policy & Terms & Conditions."
    guard let labelString = termsLabel.attributedText else {
            guard let privacyRange = labelString.string.range(of: "Privacy Policy") else {
            guard let termsConditionRange = labelString.string.range(of: "Terms & Conditions") else {
            let privacyNSRange: NSRange = labelString.string.nsRange(from: privacyRange)
            let termsNSRange: NSRange = labelString.string.nsRange(from: termsConditionRange)
            termsLabel.addLink(to: URL(string: "privacy"), with: privacyNSRange)
            termsLabel.addLink(to: URL(string: "terms"), with: termsNSRange)
            termsLabel.delegate = self
            let attributedText = NSMutableAttributedString(attributedString: termsLabel.attributedText!)
            attributedText.addAttributes([NSFontAttributeName : UIFont(name: "Roboto-Medium", size: 12)!], range: termsNSRange)
            attributedText.addAttributes([NSFontAttributeName : UIFont(name: "Roboto-Medium", size: 12)!], range: privacyNSRange)
            attributedText.addAttributes([kCTForegroundColorAttributeName as String:], range: termsNSRange)
            attributedText.addAttributes([kCTForegroundColorAttributeName as String:], range: privacyNSRange)
            attributedText.addAttributes([NSUnderlineStyleAttributeName: NSUnderlineStyle.styleNone.rawValue], range: termsNSRange)
            attributedText.addAttributes([NSUnderlineStyleAttributeName: NSUnderlineStyle.styleNone.rawValue], range: privacyNSRange)
            termsLabel.attributedText = attributedText

    It would look like this
    Simulator View

    4) Finally write the delegate function of TTTAttributedLabel so that you can open links on tap

    public func attributedLabel(_ label: TTTAttributedLabel!, didSelectLinkWith url: URL!) {
        switch url.absoluteString  {
        case "privacy":
  "", presentingViewController: self)
        case "terms":
  "", presentingViewController: self)

    Swift 3:

    // apply link attributes to label.attributedString, then
    label.tintColor = // any color you want