当前位置: 首页 > news >正文

德阳 网站建设做简历的网站 知乎

德阳 网站建设,做简历的网站 知乎,安徽网新网站建设,大麦网的网站建设苹果在iOS7中推出了一个新的类NSTextAttachment#xff0c;它是做图文混排的利器#xff0c;本文就是用这个类#xff0c;只用50行代码实现文字与表情混排#xff0c;当然也可以实现段落中的图文混排。 首先说一下文字和表情的混排#xff1a; 先来做点儿准备工作#… 苹果在iOS7中推出了一个新的类NSTextAttachment它是做图文混排的利器本文就是用这个类只用50行代码实现文字与表情混排当然也可以实现段落中的图文混排。  首先说一下文字和表情的混排  先来做点儿准备工作搞一个存放表情信息的plist文件  NSString *filePath [[NSBundle mainBundle] pathForResource:Image ofType:plist];NSArray *face [NSArray arrayWithContentsOfFile:filePath];NSMutableAttributedString *attributeString [[NSMutableAttributedString alloc] initWithString:text];NSString *regex_emoji \\[[a-zA-Z0-9\\/\\u4e00-\\u9fa5]\\];//匹配表情NSError *error nil;NSRegularExpression *re [NSRegularExpression regularExpressionWithPattern:regex_emoji options:NSRegularExpressionCaseInsensitive error:error];if(!re) {NSLog(%, [error localizedDescription]);return attributeString;}NSArray *resultArray [re matchesInString:text options:0 range:NSMakeRange(0, text.length)];NSMutableArray *imageArray [NSMutableArray arrayWithCapacity:resultArray.count];//根据匹配范围来用图片进行相应的替换for(NSTextCheckingResult *match in resultArray) {//获取数组元素中得到rangeNSRange range [match range];//获取原字符串中对应的值NSString *subStr [text substringWithRange:range];for(int i 0; i face.count; i ) {if([face[i][cht] isEqualToString:subStr]) {//face[i][png]就是我们要加载的图片//新建文字附件来存放我们的图片,iOS7才新加的对象NSTextAttachment *textAttachment [[NSTextAttachment alloc]init];//给附件添加图片textAttachment.image [UIImage imageNamed:face[i][png]];//调整一下图片的位置,如果你的图片偏上或者偏下调整一下bounds的y值即可textAttachment.boundsCGRectMake(0, -8, textAttachment.image.size.width, textAttachment.image.size.height);//把附件转换成可变字符串用于替换掉源字符串中的表情文字NSAttributedString *imageStr [NSAttributedString attributedStringWithAttachment:textAttachment];//把图片和图片对应的位置存入字典中NSMutableDictionary *imageDic [NSMutableDictionary dictionaryWithCapacity:2];[imageDic setObject:imageStr forKey:image];[imageDic setObject:[NSValue valueWithRange:range]forKey:range];//把字典存入数组中[imageArray addObject:imageDic];}}}//4、从后往前替换否则会引起位置问题for(int i (int)imageArray.count-1; i 0; i--) {NSRange range;[imageArray[i][range] getValue:range];//进行替换[attributeString replaceCharactersInRange:range withAttributedString:imageArray[i][image]];}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485861234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 以上代码段是写了一个工具类以实现图文混排也可以为NSString写一个分类来实现。下面说一下用法 NSString *content 文字加上表情[得意][酷][呲牙];NSMutableAttributedString *attrStr [Utility emotionStrWithString:content];_contentLabel.attributedText attrStr; 123456123456 有了上面的方法要实现图片和文字的排布就更容易了只需要将某些图片给它设置一个固定的字符对应即可。  具体方法如下  NSString *praiseStr ”路人甲、路人乙”; NSString *praiseInfo [NSString stringWithFormat:”点赞 %”,praiseStr]; NSDictionary *attributesForAll {NSFontAttributeName:[UIFont systemFontOfSize:14.0],NSForegroundColorAttributeName:[UIColorgrayColor]}; NSMutableAttributedString*attrStr [Utility exchangeString:”点赞”withText:praiseInfoimageName:”dynamic_love_blue”]; 有什么不足或者bug欢迎及时沟通
http://www.zqtcl.cn/news/594048/

相关文章:

  • 二手车网站建站网站建设企业建站要求
  • 海山免费网站建设做视频网站如何赚钱
  • 网站增加点击率 怎样做小店面设计装修网
  • 一 美食 视频网站模板下载安装外国优秀网站欣赏
  • 网站服务器部署重庆涪陵网站建设公司
  • php网站开发实践要做网站照片怎么处理
  • 网站短期就业培训班搜集关键词的网站
  • 社区网站开发淘宝网站打算找人做
  • 政务类网站网页管理平台
  • 淘宝联盟微信里做网站花卉市场网站建设基本步骤
  • 做网站广告语网站注册建设
  • 仓山福州网站建设哪个是网站建设里面的
  • 开网站流程开发公司起名
  • 免费建站优化网站基本设置
  • 网站建设需要上传数据库吗seo自己做网站吗
  • 网站制作ppt杭州网站的特点
  • 美丽寮步网站建设价钱杭州网站设计询问蓝韵网络
  • 毕节网站建设公司网站职业技术培训学校
  • 果洛wap网站建设比较好17岁在线观看免费高清完整版
  • 一级a做爰片在线看免播放器网站一个网站突然打不开
  • 聊城网站开发培训wordpress实时预览载入中
  • 网站设计文章国际转运网站建设
  • 南充市建设厅官方网站购物网站设计说明
  • 防疫网站网页设计wordpress不同侧边栏
  • 网站的建设多少钱长春市招标建设信息网
  • 网站加速代码百度浏览器app
  • 关于配色的网站企业宣传册文案范文
  • 免费推广网站教程湖南中核建设工程公司官方网站
  • 莱阳网站建设公司彩票类网站是如何做代理的
  • 食品公司网站建设广州做网站制作公司