Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting text color on links doesn't work in 3.5.3 #167

Open
rhfung opened this issue Nov 6, 2013 · 1 comment
Open

Setting text color on links doesn't work in 3.5.3 #167

rhfung opened this issue Nov 6, 2013 · 1 comment

Comments

@rhfung
Copy link

rhfung commented Nov 6, 2013

Setting the text color on links in 3.4.3 works as expected, so this must be a new bug.

Here's the code I am using.

NSMutableAttributedString* addressStr = /*...*/;
NSRange someRange = /* range */;
[addressStr setLink:[NSURL URLWithString:@"location://store"] range:someRange];
[addressStr setTextColor:[UIColor clearColor] range:someRange];
addressStr.userInteractionEnabled = NO;
@AliSoftware
Copy link
Owner

Hi @rhfung

I don't recall changing anything regarding text color between 3.4.3 and 3.5.3 (see diff here, especially this line).
Are you sure this change in behavior you are talking about is not because some changes between your current iOS versions and an older one?

Anyway, setLink:range: only adds an attribute (containing the URL) to the NSUAttributedString, and never changed the color of the text at all.
If the links are colored in blue in OHAttributedLabel that's not because they are blue in the original NSAttributedString, but because OHAttributedLabel itself adds the link color when drawing the text.

If you want to override the color of the link, you can either:

  • Change the linkColor property of your OHAttributedLabel — that will change the color for ALL links but only for the given OHAttributedLabel
  • or change [[OHAttributedLabel appearance] setLinkColor:] (as this propery is a UI_APPEARANCE_SELECTOR so can be used with the appearance proxy) — that will change the color for ALL links for ALL OHAttributedLabels in your app (that's what Apple's UIAppearance proxy are for after all)
  • or affect a delegate to your OHAttributedLabel and implement OHAttributedLabelDelegate's -attributedLabel:colorForLink:underlineStyle: method — this will allow you to give a different color to each of your links, allowing you to treat each link separately, for example treat NSURL whose scheme is @"location" differently from the others.

PS : Your call userInteractionEnabled = NO on the NSMutableAttributedString object makes no sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants