文件名称:ios-包装了一个富文本类.zip
文件大小:7KB
文件格式:ZIP
更新时间:2022-07-31 13:21:07
图文混排
//获取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;
【文件预览】:
SHMatching.m
SHAttributedString.h
SHMatching.h
SHAttributedString.m