美文网首页
关于字符串遍历

关于字符串遍历

作者: 那是什么 | 来源:发表于2016-10-31 12:01 被阅读13次

    NSDataDetector * _detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];

    NSArray *_urlMatches = [_detector matchesInString:self.model.content options:0 range:NSMakeRange(0, self.model.content.length)];

    for (NSTextCheckingResult *match in _urlMatches) {

    if ([match resultType] == NSTextCheckingTypeLink) {

    NSRange matchRange = [match range];

    if ([self isIndex:index inRange:matchRange]) {

    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:matchRange];

    }

    else {

    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:matchRange];

    }

    [attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:matchRange];

    }

    }

    相关文章

      网友评论

          本文标题:关于字符串遍历

          本文链接:https://www.haomeiwen.com/subject/gwbojttx.html