Open rhfung opened 10 years ago
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:
linkColor
property of your OHAttributedLabel
— that will change the color for ALL links but only for the given OHAttributedLabel
[[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)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
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.