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篇,后续还将持续更新. ...
随机推荐
- 機器學習基石 机器学习基石 (Machine Learining Foundations) 作业2 Q16-18 C++实现
大家好,我是Mac Jiang,今天和大家分享Coursera-NTU-機器學習基石(Machine Learning Foundations)-作业2 Q16-18的C++实现.尽管有非常多大神已经 ...
- No unique bean of type [net.shougongfang.action.paymoney.AlipayPayMoneyReturnObj] is defined: Unsat
0 你把@Service放到实现类上吧.这个问题好像不止一个人在问啦 2013年10月25日 10:34 shidan66 30 0 1 1 加入评论 00 1,@service放到实现上 2. ...
- HTML5开发移动web应用——Sencha Touch篇(8)
DataView是Sencha Touch中最重要的组件,用于数据的可视化.数据可视化的重要性不言而喻,能够讲不论什么数据以形象的方式展示给用户. 眼下,怎样更好地可视化是很多公司或框架都在追求的. ...
- 2016.3.17__ JavaScript基础_1__第十二天
Javascript基础 首先说声抱歉. 今日涉及内容难易度不统一,所以很多比較基础的属性直接通过思维导图展示了. 同一时候须要注意,今日思维导图中的内容和笔记中并非一一相应的,请读者自行对比查看. ...
- Android UI 优化 使用<include/>和 <merge />标签
使用<include /> 标签来重用layout代码 如果在一个项目中需要用到相同的布局设计,可以通过<include /> 标签来重用layout代码,该标签在Androi ...
- MySql悲观锁总结与实践
mysql(for update)悲观锁总结与实践 https://blog.csdn.net/zmx729618/article/details/52701972 悲观锁,正如其名,它指的是对数据被 ...
- SpringBoot项目部署
项目背景 个人博客:http://www.huangyichun.cn/blog/8 采用SpringBoot开发的个人博客,部署到腾讯云服务器上,服务器系统为ubuntu16.04, ...
- 绘图中的drawRect
rect参数:代表的是当前view的bounds 1 为什么要在drawRect方法里面写绘图代码 因为只有在这个方法中才能获取到当前view相关的图形上下文对象 有了这个图形上写文对象后才能进行绘图 ...
- CSS大纲
- RabbitMQ学习笔记(1)----RabbitMQ简介与安装
·1. 什么是RabbitMQ? RabbitMQ是流行的开源消息队列系统,用erlang语言开发.RabbitMQ是AMQP(高级消息队列协议)的标准实现. 而AMQP协议则是指:即Advanced ...