AliSoftware / OHAttributedLabel

UILabel that supports NSAttributedString
https://github.com/AliSoftware/OHAttributedLabel/wiki
1.51k stars 344 forks source link

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

Open rhfung opened 10 years ago

rhfung commented 10 years ago

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 commented 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:


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