去年基于5.0开发的时候。自己用coreText编写了一个富文本,全部的效果都实现的非常好。可是没有去測试效率。只是在cell重用的时候表现不错。在4s上面也不会卡顿。

唯一一个问题就是,在使用AL的时候。不方便。

所以,此次新版本号是基于7.0开发。决定使用textkit又一次编写一次。

以下是一些主要的使用:

@interface MMTextAttachment : NSTextAttachment
{ } @end @implementation MMTextAttachment //I want my emoticon has the same size with line's height
- (CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)lineFrag glyphPosition:(CGPoint)position characterIndex:(NSUInteger)charIndex NS_AVAILABLE_IOS(7_0)
{
NSLog(@"\n lineFrag={%f,%f,%f,%f} \n",lineFrag.origin.x,lineFrag.origin.y,lineFrag.size.width,lineFrag.size.height);
NSLog(@"\n glyphPosition={%f,%f} \n",position.x,position.y);
CGFloat lineHeight = lineFrag.size.height;
CGFloat abc = 21.0;
return CGRectMake( 0 , (lineHeight - abc)/2.0 , abc , abc);
}

能够使用UITextView 或 UILabel,可是UITextView能够检測链接等。以下先看下UITextView

// 点击处理
// http://stackoverflow.com/questions/19332283/detecting-taps-on-attributed-text-in-a-uitextview-on-ios-7
NSMutableAttributedString * string = [[ NSMutableAttributedString alloc ] initWithString:@"1@谭中洞 2345678910 http://gutou.com 1112what happendwhatg一个地址 重庆市渝中区210号 02364646464 happendwhat happendwhat happendwhat happendwhat happend This is an example by @marcelofabri_ #abcdef " attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14.0]} ] ;
MMTextAttachment * textAttachment = [[ MMTextAttachment alloc ] initWithData:nil ofType:nil ] ;
textAttachment.image = [UIImage imageNamed:@"002.png"] ;
NSAttributedString * textAttachmentString = [ NSAttributedString attributedStringWithAttachment:textAttachment ] ;
[string insertAttributedString:textAttachmentString atIndex:7] ; MMTextAttachment * textAttachmen2t = [[ MMTextAttachment alloc ] initWithData:nil ofType:nil ] ; [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:@"https://www.baidu.com/img/baidu_jgylogo3.gif?v=27357745.gif"] options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
// 使用网络下载,下载完毕后,又一次刷新下这个range
textAttachmen2t.image = image;
[_textView.layoutManager invalidateDisplayForCharacterRange:NSMakeRange(57, 1)]; // UILabel能够使用<span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);">setNeedsDisplay
</span> }]; NSAttributedString * textAttachmentStr2ing = [ NSAttributedString attributedStringWithAttachment:textAttachmen2t ] ;
[string insertAttributedString:textAttachmentStr2ing atIndex:57] ;
//
NSRange range1 = [[string string] rangeOfString:@"@marcelofabri_"];
[string addAttribute:NSLinkAttributeName
value:@"URL://jsonstring"
range:range1];
NSLog(@"\n range1 = %@ \n",NSStringFromRange(range1));
NSRange range2 = [[string string] rangeOfString:@"#abcdef "];
[string addAttribute:NSLinkAttributeName
value:@"URL://jsonstring"
range:range2];
NSLog(@"\n range2 = %@ \n",NSStringFromRange(range2)); // [string addAttributes:@{NSForegroundColorAttributeName: [UIColor blueColor]} range:range1];
// [string addAttributes:@{NSForegroundColorAttributeName: [UIColor greenColor]} range:range2]; /*
// 自定link的颜色
NSDictionary *linkAttributes = @{
NSForegroundColorAttributeName: [UIColor blueColor],
NSUnderlineColorAttributeName: [UIColor redColor],
NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid)
};
_textView.linkTextAttributes = linkAttributes; // customizes the appearance of links
*/
_textView.dataDetectorTypes = UIDataDetectorTypeLink;
_textView.attributedText = string ;
_textView.selectable = YES; // 才干实现点击delegate
_textView.scrollEnabled = NO;// 设置为AL后才会自己主动算高
_textView.editable = NO;
_textView.delegate = self;

实现UITextViewDelegate

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange

以上能够看到,网络下载,@等URL就都能够实现了。可是因为APPLE 在UITextView中把非常多方法都实现了。所以导致。并不能非常好的控制。

比方URL检測,全部的URL都会被检測出来。另外@、#等为了表现为不同的颜色,也不好控制了。

另一个,我不知道怎么解决的是:当点击链接的时候,就算是手指滑出链接范围。delegate还是会触发,这个不太好。另一种推断点击,大家能够參考 

http://stackoverflow.com/questions/19332283/detecting-taps-on-attributed-text-in-a-uitextview-on-ios-7

明天准备花一天时间,结合曾经写过的又一次编写一次。假设有啥兴许再补充。

之前写过的解析有表情,@ ## 等能够点击的URL,以下是效果图

不知道为什么底部会加入一个版权全部。我了个去~~ 随便转,不要看以下的,(可是也请注明出处).

IOS7 textkit 的相关的更多相关文章

  1. 关于iOS7的一切相关的资料

    http://www.cocoachina.com/special/ios7/ PreviousNext 作为的用户,您可能需要了解 WWDC大会以及iOS 7的新界面 CocoaChina WWDC ...

  2. 嵌入式单片机STM32应用技术(课本)

    目录SAIU R20 1 6 第1页第1 章. 初识STM32..................................................................... ...

  3. iOS7下status bar相关问题的解决方法

    转载自:http://blog.csdn.net/volcan1987/article/details/14227313 iOS7里status bar的实现跟iOS6下有写不一样,前段时间碰到了这个 ...

  4. ios7 导航栏 手势 右划 自动返回 相关

    http://www.tuicool.com/articles/vMfAVv 纪录一下,

  5. Dynamic支持CollectionView布局 、 MotionEffects特效 、 BlurImage效果 、 TextKit

    1 使用UIDynamicAnimator对集合视图进行布局 1.1 问题 UIKit Dynamic动力模型一个非常有趣的用途就是影响集合视图的布局,可以给集合视图的布局添加各种动力行为,使其产生丰 ...

  6. iOS7开发中的新特性

        iOS7到现在已经发布了有一段时间了.相信你现在已经了解了它那些开创性的视觉设计,已经了解了它的新的API,比如说SpirteKit,UIKit Dynamics以及TextKit,作为开发者 ...

  7. 2.1 -1.0 Xcode(发布时间、使用、快捷键、插件相关)

    本文并非最终版本,如有更新或更正会第一时间置顶,联系方式详见文末 如果觉得本文内容过长,请前往本人 “简书” 1.0 Xcode 发布时间 版本 iOS 版本 手机 日期 特殊介绍 Xcode 3.1 ...

  8. 问你觉得iOS7为什么要扁平化,扁平化和之前的比有什么优势

    问你觉得iOS7为什么要扁平化,扁平化和之前的比有什么优势 苹果首席设计师谈为何会在iOS上选择扁平风格http://ndnews.oeeee.com/html/201306/11/71078.htm ...

  9. 升级到iOS9之后的相关适配

    iOS9AdaptationTips(iOS9开发学习交流群:458884057) iOS9适配系列教程[中文在页面下方]转自@iOS程序犭袁 (截至2015年9月26日共有10篇,后续还将持续更新. ...

随机推荐

  1. Gzip压缩优化网站

    网站常使用GZIP压缩算法对网页内容进行压缩,然后传给浏览器,以减小数据传输量,提高响应速度.浏览器接收到GZIP压缩数据后会自动解压并正确显示.GZIP加速常用于解决网速慢的瓶颈. 压缩Filter ...

  2. git在win7下安装的问题

    本帖最后由 ikscher 于 2015-07-30 20:24:16 编辑 从官网下载的最新版本号git-1.9.2-preview版本号,安装在还有一台win7下没有此错误,可是安装在当中一台出现 ...

  3. zzulioj--1637--Happy Thanksgiving Day - WoW yjj!(水)

    1637: Happy Thanksgiving Day - WoW yjj! Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 104  Solved: ...

  4. Thread.setDaemon设置说明

    转载地址:http://blog.csdn.net/m13666368773/article/details/7245570 Thread.setDaemon的用法,经过学习以后了解: 1. setD ...

  5. ROS-Rviz-turtlebot3仿真信息查看

    前言:Rviz是ROS自带的一种3D可视化工具. 一.安装turtlebot3功能包 1.1 安装依赖包 sudo apt-get install ros-kinetic-joy ros-kineti ...

  6. WIN7把任务栏的的蓝牙图标误删了找回方法

    当时我删了以后,在网上找方法,都说—— 点击任务栏下面的三角箭头,选择自定义,里面有蓝牙图标选项,选择显示图标和通知. 可是我发现我的自定义选项里面就没有蓝牙图标选项啊... 故事的最后,我终于找到了 ...

  7. vue入门--简单路由配置

    在初始化vue init webpack <工程名>时,有一步是询问是否安装vue-router,选择yes,如果没有安装的话,后面需要自己安装.然后在目录中可以看到有个文件夹叫route ...

  8. javascript动画函数封装(升级版)

    //把 任意对象 的 任意数值属性 改变为 任意的目标值 function animate(obj, json, fn) { clearInterval(obj.timer); obj.timer = ...

  9. webpack 参数1、context: path.resolve 2、path.join('', '..', 'aa') 3、 path.posix.join('static','/aa')

    1.context: path.resolve 项目入口路径 2. 3.

  10. innerHTML 与 outerHTML区别

    示例代码: <div id="test"> <p>这是innerHTML</p> <p>这是innerHTML</p> ...