包装了一个富文本类
//获取url数组
NSArray *urlArr = [SHMatching urlArrWithString:str];
//电话
NSArray *phoneArr = [SHMatching phoneNumArrWithString:str];
//邮箱
NSArray *emailArr = [SHMatching emailStringArrWithString:str];
NSAttributedString *att_str1 = [[NSAttributedString alloc]initWithString:str];
//识别url
NSAttributedString *attstr = [SHAttributedString attributedStringWithString:str andUrlStringName:nil line:NO];
//指定url名称
attstr = [SHAttributedString attributedStringWithAttString:att_str1 andUrlStringName:@"百度" urlStr:@"http://www.baidu.com" line:YES];
attstr = [SHAttributedString attributedStringWithAttString:attstr andUrlStringName:@"微博" urlStr:@"http://www.weibo.com"line:YES];
//改变指定位置文字颜色
NSAttributedString *att_str = [SHAttributedString attributedStringWithAttributedString:attstr andColor:[UIColor blackColor] font:[UIFont fontWithName:@"Arial" size:20] range:NSMakeRange(0, attstr.length)];
//插入图片
att_str = [SHAttributedString attributedStringWithAttributedString:att_str insertImage:[UIImage imageNamed:@"compose_emoticonbutton_background_highlighted@2x"] atIndex:3];
//识别电话
att_str = [SHAttributedString attributedPhoneStringWithString:att_str insertImage:[UIImage imageNamed:@"chatBar_colorMore_audioCallSelected@2x"] orPhoneNameString:nil isCall:NO];
//识别邮箱
att_str = [SHAttributedString attributedEmailStringWithString:att_str insertImage:[UIImage imageNamed:@"compose_emoticonbutton_background_highlighted@2x"] orEmailNameString:@"邮箱"];
//计算size
CGSize size = [SHAttributedString attributedStringSizeWithAttString:att_str preinstallSize:CGSizeMake(self.view.frame.size.width-20, MAXFLOAT)];
self.myTextView.attributedText = att_str;
下载地址:http://www.wenjiangs.com/wp-content/uploads/2021/docimg35/2202d1e5dbed617df834dc06ef12e81e.zip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论