Make link in UILabel.attributedText *not* blue and *not* underlined

前端 未结 11 1231
终归单人心
终归单人心 2020-12-24 05:18

I want some words within my OHAttributedLabel to be links, but I want them to be colors other than blue and I don\'t want the underline.

This is giving me a blue lin

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 05:50

    So I ended up using TTTAttributedLabel:

    -(void)createLinkFromWord:(NSString*)word withColor:(UIColor*)color atRange:(NSRange)range{
        NSMutableAttributedString* newTextWithLinks = [self.label.attributedText mutableCopy];
        NSURL *url = [NSURL URLWithString:@"http://www.reddit.com"];
        self.label.linkAttributes = @{NSForegroundColorAttributeName: color, 
                                       NSUnderlineStyleAttributeName: @(NSUnderlineStyleNone)};
        [self.label addLinkToURL:url withRange:range];
    }
    

    I found that OHAttributedLabel actually does have methods to set links and declare colors and underline styles for those links. However, I wanted the links to be different colors based on a parameter. TTTAttributedLabel allows this by letting you set it's linkAttributes property for each link you create.

提交回复
热议问题