给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;
}
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;
}
相关文章推荐
- 使用ASP.NET开发的网站,怎么把动态的页面静态化?
- bat programming is easy and powerful
- CentOS6.5中修改yum源
- oracle 中身份证号15位升18位
- 不重启的情况下清除网络共享的密码
- IOS添加计时器的两种方法
- Cpp--sizeof与strlen区别与联系
- U盘无法格式的解决办法
- Qt try catch排错历程——C++的异常对除零不起作用
- C&OC的数据类型分类
- 打印js插件
- Redis数据类型之有序集合类型--Redis系列六
- Linux的automake出现的问题(Makefile.am: C objects in subdir but `AM_PROG_CC_C_O' not in `configure.ac')
- CFileDialog会自动更改程序当前工作目录(解决方案)!
- C语言数组练习
- 使用UITabBarViewCOntroller时隐藏tabbar
- Ubuntu下usb设备读写权限设置
- JavaScript中JSON使用
- ios代码编写UIButton,设置图片,图片不显示
- Google地图API方式查看卫星地图