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篇,后续还将持续更新. ...
随机推荐
- Android scrollTo() scrollBy() Scroller解说及应用
版本号:1.0 日期:2014.6.17 2014.6.18 版权:© 2014 kince 转载注明出处 scrollTo() .scrollBy()及 Scroller在视图滑动中常常使用 ...
- 关于server和虚拟主机的差别
文章都是先由本人个人博客,孙占兴:www.teilim.com,先更新,随后CSDN博客才会更新.掌握第一动态请关注本人主站. 原文链接:http://www.teilim.com/guan-yu-y ...
- qq邮箱的SMTP服务器是什么
qq邮箱的SMTP服务器是什么 QQ邮箱POP3 和 SMTP 服务器地址设置如下:POP3服务器地址为“pop.qq.com”,SMTP服务器地址为“smtp.qq.com”注:1.SMTP服务器需 ...
- RAC中的各种IP-PUBLIC-VIP-Private-SCAN IP
RAC中的各种IP-PUBLIC-VIP-Private-SCAN IP 1.PUBLIC和VIP Oracle RAC中每个节点都有一个虚拟IP,简称VIP, 与公网PUBLIC IP在同一个 ...
- DB-MySQL:MySQL 教程
ylbtech-DB-MySQL:MySQL 教程 1.返回顶部 1. MySQL 教程 MySQL 是最流行的关系型数据库管理系统,在WEB应用方面 MySQL 是最好的RDBMS(Relation ...
- 2.Matlab数值数组及其运算
2.1引导 2.2一维数组的创建与寻访 2.3二维数组的创建 2.4二维数组元素的标识 2.5二维数组的子数组寻访和赋值 2.6执行数组运算的常用函数 2.7数组运算和矩阵运算 2.8多项式的表达和创 ...
- redis的主从模式
主从通信过程 Master配置: 1:关闭rdb快照(备份工作交给slave) 2:可以开启aof slave配置: 1: 声明slave-of slaveof 192.168.0.102 2: 配置 ...
- SQL常用函数集锦
..STUFF()用另一子串替换字符串指定位置.长度的子串.STUFF (<character_expression1>, <start_ position>, <len ...
- 立即执行函数与Function
js立即执行函数: (function ( ){})( ) 与 (function ( ){}( )) 与new Function()区别? new Function() 还是有区别的,fn = ne ...
- python写的爬虫工具,抓取行政村的信息并写入到hbase里
python的版本是2.7.10,使用了两个第三方模块bs4和happybase,可以通过pip直接安装. 1.logger利用python自带的logging模块配置了一个简单的日志输出 2.get ...