IOS7 textkit 的相关
去年基于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 的相关的更多相关文章
- 关于iOS7的一切相关的资料
http://www.cocoachina.com/special/ios7/ PreviousNext 作为的用户,您可能需要了解 WWDC大会以及iOS 7的新界面 CocoaChina WWDC ...
- 嵌入式单片机STM32应用技术(课本)
目录SAIU R20 1 6 第1页第1 章. 初识STM32..................................................................... ...
- iOS7下status bar相关问题的解决方法
转载自:http://blog.csdn.net/volcan1987/article/details/14227313 iOS7里status bar的实现跟iOS6下有写不一样,前段时间碰到了这个 ...
- ios7 导航栏 手势 右划 自动返回 相关
http://www.tuicool.com/articles/vMfAVv 纪录一下,
- Dynamic支持CollectionView布局 、 MotionEffects特效 、 BlurImage效果 、 TextKit
1 使用UIDynamicAnimator对集合视图进行布局 1.1 问题 UIKit Dynamic动力模型一个非常有趣的用途就是影响集合视图的布局,可以给集合视图的布局添加各种动力行为,使其产生丰 ...
- iOS7开发中的新特性
iOS7到现在已经发布了有一段时间了.相信你现在已经了解了它那些开创性的视觉设计,已经了解了它的新的API,比如说SpirteKit,UIKit Dynamics以及TextKit,作为开发者 ...
- 2.1 -1.0 Xcode(发布时间、使用、快捷键、插件相关)
本文并非最终版本,如有更新或更正会第一时间置顶,联系方式详见文末 如果觉得本文内容过长,请前往本人 “简书” 1.0 Xcode 发布时间 版本 iOS 版本 手机 日期 特殊介绍 Xcode 3.1 ...
- 问你觉得iOS7为什么要扁平化,扁平化和之前的比有什么优势
问你觉得iOS7为什么要扁平化,扁平化和之前的比有什么优势 苹果首席设计师谈为何会在iOS上选择扁平风格http://ndnews.oeeee.com/html/201306/11/71078.htm ...
- 升级到iOS9之后的相关适配
iOS9AdaptationTips(iOS9开发学习交流群:458884057) iOS9适配系列教程[中文在页面下方]转自@iOS程序犭袁 (截至2015年9月26日共有10篇,后续还将持续更新. ...
随机推荐
- Manarcher 求 字符串 的最长回文子串 【记录】
声明:这里仅仅写出了实现过程.想学习Manacher的能够看下这里给出的实现过程,算法涉及的一些原理推荐个博客. 给个链接 感觉讲的非常细 引子:给定一个字符串s,让你求出最长的回文子串的长度. 算法 ...
- spring batch(一):基础部分
spring batch(一):基础部分 博客分类: Spring java spring batch 官网: http://www.springsource.org/spring-batch 下 ...
- SAM学习笔记
SAM学习笔记 后缀自动机(模板)NSUBSTR(Caioj1471 || SPOJ 8222) [题意] 给出一个字符串S(S<=250000),令F(x)表示S的所有长度为x的子串中,出现次 ...
- DNS反射放大攻击分析——DNS反射放大攻击主要是利用DNS回复包比请求包大的特点,放大流量,伪造请求包的源IP地址为受害者IP,将应答包的流量引入受害的服务器
DNS反射放大攻击分析 摘自:http://www.shaojike.com/2016/08/19/DNS%E6%94%BE%E5%A4%A7%E6%94%BB%E5%87%BB%E7%AE%80%E ...
- Android接口回调的理解
1.各种理解 <1>说白了,就是拿到对象引用,调其方法 <2>实际上就是利用多态的方式调用而已 <3>其实很容易理解的,定义接口,然后提供一个外部的接口设置进去,然 ...
- java 读写分离
源码地址:http://git.oschina.net/xiaochangwei 先回答下 1.为啥要读写分离? 大家都知道最初开始,一个项目对应一个数据库,基本是一对一的,但是由于后来用户及数据还有 ...
- 【AnjularJS系列4 】 — 单个页面加载多个ng-App
第四篇,插播, 单个页面加载多个ng-App 在写范例的时候发现的问题 一个页面有多个ng-app,angular只会处理第一个ng-app 需要加载两个ng-app,需要进行手动加载: angula ...
- Unity 三维软件单位导入资源单位比例
三维软件 内部米制尺寸/m 默认设置导入unity中的尺寸/m 与unity单位比例 Maya 1 100 1:100 3DS MAX 1 0.01 100:1 Cinema 4D 1 100 1:1 ...
- ZBrush中SnakeHook蛇钩笔刷介绍
不同笔刷用着不同的作用,绘画出来的效果也是千姿百态,各有千秋,有些笔刷在使用的时候可以替代,但有些笔刷是无法替代,不可超越的,比如ZBrush®中给我们提供的,SnakeHook笔刷,该笔刷在模型表面 ...
- ZBrush软件特性之Marker标记调控板
在ZBrush®中使用Marker标记调控板来记忆物体属性,因此能在任何时间回到标记并使用它给其他物体或改变物体作为参考点. ZBrush软件下载:http://pan.baidu.com/s/1sl ...