Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting NSLinkAttributeName font color

Tags:

I feel like I'm missing something easy but I can't seem to find out how to do this:

I set the attribute to a link like so:

[myAttrString addAttribute:NSLinkAttributeName value:linkURL range:selectedRange]; 

That works but the link is blue and I can't seem to change the color. This sets everything except the link to white:

[myAttrString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:selectedRange]; 

Is there another color attribute name that I can't seem to find that is specific to links?

like image 719
Oren Avatar asked Aug 22 '14 23:08

Oren


2 Answers

  1. Use a UITextView
  2. Set the UITextView's linkTextAttributes like so:

    textView.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]}; 
like image 188
Justin Moser Avatar answered Oct 05 '22 19:10

Justin Moser


I actually ended up using TTTAttributedLabel for my label and then was able to do the following which worked perfectly:

NSDictionary *linkAttributes = @{(id)kCTForegroundColorAttributeName: [UIColor whiteColor],                                  (id)kCTUnderlineStyleAttributeName: [NSNumber numberWithInt:kCTUnderlineStyleSingle]                                  }; self.lblDescription.linkAttributes = linkAttributes;     
like image 45
Oren Avatar answered Oct 05 '22 19:10

Oren