2013-10-30 112 views
1

我用RTLabel从https://github.com/honcheng/RTLabel 我需要使用文本链接,我用:RTLabel问题(粗体链接)

moreInfoString = [NSString stringWithFormat:@"%@ <a href='%@'>%@</a>", text, httpReferense, title]; 
RTLabel *descriptionSourceLabel = [[RTLabel alloc] init]; 
descriptionSourceLabel.backgroundColor = [UIColor clearColor]; 
descriptionSourceLabel.delegate = self; 
[descriptionSourceLabel setText:moreInfoString]; 

但文字是联系是大胆的。如何取消链接中的粗体文本?

回答

1

我认为我的方式不是最好的,但无论如何:

- (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]; 
     } 
+0

下面的链接属性解决方案应该是正确的 – jyek

2

linkAttributes属性可用于链接的自定义样式。如果您将linkAttributes设置为空字典,则链接将不会被设置样式。

// Remove all link styles 
descriptionSourceLabel.linkAttributes = @{}; 

// To change only i.e. link color 
descriptionSourceLabel.linkAttributes = @{@"color": @"red"};