您的位置:首页 > 其它

给URL标示特别颜色

2015-10-21 17:05 302 查看
- (NSMutableAttributedString *)filterLinkWithContent:(NSString *)content {

NSMutableAttributedString *attributedString = [[NSMutableAttributedString
alloc]
initWithString:content];

NSError *error = NULL;

NSDataDetector *detector =

[NSDataDetector
dataDetectorWithTypes:(NSTextCheckingTypes)NSTextCheckingTypeLink |
NSTextCheckingTypePhoneNumber

error:&error];

NSArray *matches = [detector
matchesInString:content

options:0

range:NSMakeRange(0, [content
length])];

for (NSTextCheckingResult *match
in matches) {

if (([match
resultType] == NSTextCheckingTypeLink)) {

NSURL *url = [match
URL];
[attributedString
addAttribute:NSLinkAttributeName
value:url range:match.range];
}
}

return attributedString;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: