我认为我的方式不是最好的,但无论如何:
在- (void)render
我替换的功能中:
else if ([component.tagLabel caseInsensitiveCompare:@"a"] == NSOrderedSame)
{
if (self.currentSelectedButtonComponentIndex==index)
{
if (self.selectedLinkAttributes)
{
[self applyFontAttributes:self.selectedLinkAttributes toText:attrString atPosition:component.position withLength:[component.text length]];
}
else
{
[self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
[self applyColor:@"#FF0000" toText:attrString atPosition:component.position withLength:[component.text length]];
}
}
else
{
if (self.linkAttributes)
{
[self applyFontAttributes:self.linkAttributes toText:attrString atPosition:component.position withLength:[component.text length]];
}
else
{
[self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
[self applySingleUnderlineText:attrString atPosition:component.position withLength:[component.text length]];
}
}
NSString *value = [component.attributes objectForKey:@"href"];
value = [value stringByReplacingOccurrencesOfString:@"'" withString:@""];
[component.attributes setObject:value forKey:@"href"];
[links addObject:component];
}
与(添加了 linkShouldBe_regularFont 属性 - 我的自定义属性,如果 linkShouldBe_regularFont == YES,字体将是常规的):
else if ([component.tagLabel caseInsensitiveCompare:@"a"] == NSOrderedSame)
{
if (self.currentSelectedButtonComponentIndex==index)
{
if (self.selectedLinkAttributes)
{
[self applyFontAttributes:self.selectedLinkAttributes toText:attrString atPosition:component.position withLength:[component.text length]];
}
else
{
if (!self.linkShouldBe_regularFont) {
[self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
}
[self applyColor:@"#FF0000" toText:attrString atPosition:component.position withLength:[component.text length]];
}
}
else
{
if (self.linkAttributes)
{
[self applyFontAttributes:self.linkAttributes toText:attrString atPosition:component.position withLength:[component.text length]];
}
else
{
if (!self.linkShouldBe_regularFont) {
[self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
}
[self applySingleUnderlineText:attrString atPosition:component.position withLength:[component.text length]];
}
}
NSString *value = [component.attributes objectForKey:@"href"];
value = [value stringByReplacingOccurrencesOfString:@"'" withString:@""];
[component.attributes setObject:value forKey:@"href"];
[links addObject:component];
}