效果图:
/*
注意事项:
1.使用之前需要倒入 libicucore.dylib And CoreText.framework
2.此类使用了ARC管理内存
3.如果你的项目是非ARC项目,你需要在文件添加-fobjc-arc的标示(非ARC标示-fno-objc-arc)
*/
使用方法:
//7.文本
WXLabel *text = [[WXLabel alloc] init];
[self.topView addSubview:text];
text.font = textFont;
text.numberOfLines = 0;
[text sizeToFit];
// text.colorName = @"Theme_Main_color";
self.text = text;
self.text.wxLabelDelegate = self;
#pragma mark - WXLabelDelegate
//(1)检索文本的正则表达式的字符串
- (NSString *)contentsOfRegexStringWithWXLabel:(WXLabel *)wxLabel {
//@某人 #话题# http(s)://......
//@某人
NSString *people = @"@\\w+";
//#话题#
NSString *topic = @"#[^#]+#";
//网址 http(s)://www.baidu.com/www.baidu.com/www.baidu.com/
// NSString *regex3 = @"http(s)?://([a-zA-Z0-9._-]+(/)?)*";
// NSString *regex3 = @"http(s)?://([a-zA-Z0-9._-/?]+)*";
NSString *httpStr = @"\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?";
NSString *result = [NSString stringWithFormat:@"%@|%@|%@",people,topic,httpStr];
return result;
}
//(2)设置当前超链接的颜色
- (UIColor *)linkColorWithWXLabel:(WXLabel *)wxLabel {
UIColor *color = [[ThemeManager shareInstance] getThemeColor:@"Link_color"];
return color;
}
//(3)设置当前文本手指经过的颜色
- (UIColor *)passColorWithWXLabel:(WXLabel *)wxLabel {
UIColor *color = [UIColor grayColor];
return color;
}
//(4)点击超链接响应的代理方法
//context里面是设置的正则检索字符串,此方法在点击这些字符串时会调用
- (void)toucheEndWXLabel:(WXLabel *)wxLabel withContext:(NSString *)context {
NSLog(@"context:%@",context);
}
类库链接: http://pan.baidu.com/s/1nt47LKt 密码: qrei