识别URL的正则表达式:
((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\\.\\-~!@#$%^&*+?:_/=<>]*)?)
可以通过分类的方式给label添加个分类, 为label新增个分类方法:.h文件
#import <UIKit/UIKit.h>
@interface UILabel (LinkUrl)
- (void)setTextWithLinkAttribute:(NSString *)text;
@end
.m文件
#import "UILabel+LinkUrl.h"
@implementation UILabel (LinkUrl)
- (void)setTextWithLinkAttribute:(NSString *)text {
self.attributedText = [self subStr:text];
}
-(NSMutableAttributedString*)subStr:(NSString *)string
{
NSError *error;
//可以识别<