<原>DTCoreText学习(一)-DTAttributedTextCell原理
2012-09-02 14:18
281 查看
其实DTCoreText自带的cell就很好用了,解析html并且显示html都很方便,只要设置DTAttributedTextCell的
- (void)setHTMLString:(NSString *)html方法即可,其原理如下面所示
这是DTAttributedTextCell中定义的初始化方法 在cell的contentView上覆盖了一层DTAttributedTextContentView 而我们的html正是通过它显示出来的,
_attributedString的类型是NSAttributedString 我们把要显示的html传递给 setHTMLString:(NSString *)html 最后调用self.attributedString = string; 后进入setAttributedString:(NSAttributedString *)attributedString
最终设置 _attributedTextContextView.attributedString = _attributedString;达到显示的目的
DTAttributedTextCell常用的就这几个方法 一般了解这几个方法的使用 就能简单的实现利用 DTAttributedTextCell解析并显示html
- (void)setHTMLString:(NSString *)html方法即可,其原理如下面所示
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier accessoryType:(UITableViewCellAccessoryType)accessoryType { self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]; if (self) { // don't know size jetzt because there's no string in it _attributedTextContextView = [[DTAttributedTextContentView alloc] initWithFrame:CGRectZero]; _attributedTextContextView.edgeInsets = UIEdgeInsetsMake(5, 5, 5, 5); [self.contentView addSubview:_attributedTextContextView]; } return self; }
这是DTAttributedTextCell中定义的初始化方法 在cell的contentView上覆盖了一层DTAttributedTextContentView 而我们的html正是通过它显示出来的,
- (void)setHTMLString:(NSString *)html { // we don't preserve the html but compare it's hash NSUInteger newHash = [html hash]; if (newHash == _htmlHash) { return; } _htmlHash = newHash; NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding]; NSAttributedString *string = [[NSAttributedString alloc] initWithHTML:data documentAttributes:NULL]; self.attributedString = string; } - (void)setAttributedString:(NSAttributedString *)attributedString { if (_attributedString != attributedString) { _attributedString = attributedString; // passthrough _attributedTextContextView.attributedString = _attributedString; } }
_attributedString的类型是NSAttributedString 我们把要显示的html传递给 setHTMLString:(NSString *)html 最后调用self.attributedString = string; 后进入setAttributedString:(NSAttributedString *)attributedString
最终设置 _attributedTextContextView.attributedString = _attributedString;达到显示的目的
DTAttributedTextCell常用的就这几个方法 一般了解这几个方法的使用 就能简单的实现利用 DTAttributedTextCell解析并显示html
相关文章推荐
- <原>DTCoreText学习(三)-自定义DTAttributedTextCell
- <原>在一个tableView上应用不同类型的DTAttributedTextCell
- <原>DTCoreText学习(二)-DTAttributedTextCell应用
- <script type="text/html"></script> js模版使用
- <mvc:resources mapping="/js/**" location="/js/**"/> <script type="text/javascript" src="<%=reques
- <关于并发框架>Java原生线程池原理
- <Principles of fMRI 1>课程笔记3--MRI的原理
- 万恶的<table>:IE中text-overflow:elipsis无效
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">意思?
- Nutch如何读取CrawlDb中的<Text,CrawlDatum>键值对
- <关于并发框架>Java原生线程池原理及Guava与之的补充
- <dl><dt><dd>标签的作用
- <安彦>Java中JVM的原理一
- <<操作系统精髓与设计原理>>读书笔记(一) 并发性:互斥与同步(1)
- <EditText /> This text field does not specify an inputType or a hint
- <学习笔记4>数据挖掘原理与运用-sql server2008 数据库
- <html:form>、 <html:text>、<html:password>、<html:submit> 标签
- <操作系统:精髓与设计原理> 计算机系统概述
- <input name="keyword" type="text" value="请输入关键字" onFocus="this.value=''" onBlur="if(!value){value=defaultValue;}">
- <<iText in Action 2nd>>4.2节(Changing the properties of a cell)读书笔记