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?
This is surprisingly easy, text components that supports link detection have a property called
linkTextAttributes
.This property stores the style for the link as of the component can apply it when detects a new link.
Summing up, your style will be applied and then the style stored in this property (in this order), successfully overriding your desired style.
Set this property to empty (
linkTextAttributes = [:]
) and take total control of you link Styles.This works for me:
UITextView
Set the
UITextView
'slinkTextAttributes
like so:If you use TTTAttributedLabel, Oren's answer is worked.But you need to pay attention to the linkAttributes's warning in annotation.
txtLabel.linkAttributes = @{};
This is the right one, call this line before set any other attribute
For swift (for reference for others):