实例化自定义的,可点击链接的label(这个资料挺多的,我也是网上找的)
HyperlinkLabel *desLbl = [[HyperlinkLabel alloc] initWithFrame:CGRectMake(originWidth, maHeight+17*kScreenWidth_Scale, kScreenWidth-2*originWidth, 50*kScreenHeight_Scale)];
//正则表达式获取文字中的链接地址
NSError *error;
NSString *regulaStr = @"((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)";NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regulaStr
options:NSRegularExpressionCaseInsensitive
error:&error];
NSArray *arrayOfAllMatches = [regex matchesInString:desLbl.text options:0 range:NSMakeRange(0, [desLbl.text length])];
NSString* substringForMatch = @"";//substringForMatch 就是获取的最终链接地址
for (NSTextCheckingResult *match in arrayOfAllMatches)
{
substringForMatch = [desLbl.text substringWithRange:match.range];
NSLog(@"substringForMatch %@",substringForMatch);
}
if (substringForMatch.length>0) {[desLbl setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@",substringForMatch]] forRange:[desLbl.text rangeOfString:substringForMatch]];
desLbl.URLClickHandler = ^(CXAHyperlinkLabel *label, NSURL *URL, NSRange range, NSArray *textRects){
NSLog(@"超链接被点击");
[[UIApplication sharedApplication] openURL:URL];
};
}