2013-10-30 49 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"};