I have an NSTextView for which I have set default link style attributes using the -setLinkTextAttributes:
method. This is the style I wish to use for outgoing links.
In the text view I also have clickable areas that trigger functions inside the text view. I have implemented these as links. I want these to be styled independently of the outgoing links. So the logical way to write the code was like this:
[attrStr addAttribute:NSLinkAttributeName
value:@"myapp://togglesomething"
range:hlRange];
[attrStr addAttribute:NSForegroundColorAttributeName
value:[NSColor yellowColor]
range:hlRange];
But the color of the links do not change to the one i set here.
So the question is:
If you don't explicitly set the NSForegroundColorAttributeName in setLinkTextAttributes, you can override this for individual link ranges.
i.e. just set:
[_textView setLinkTextAttributes:@{NSCursorAttributeName:[NSCursor pointingHandCursor]}];
And color your link ranges like you have above.
Solution from Chen Lim worked.
[self.textView setLinkTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor],}];
As pointed in the original question. Can we have different colors for different links. setLinkTextAttributes sets the attributes for all the links.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With