让Label等控件支持HTML格式的代码? 使用NSAttributedString:
2017-08-02 15:12
495 查看
> 如何让Label等控件支持HTML格式的代码? 使用NSAttributedString:
NSString *htmlString = @"<div>Tate<span style='color:#1C86EE;'>《iOS Develop Tips》</span>get <span style='color:#1C86EE;'>Tate_zwt</span> 打赏 <span style='color:#FF3E96;'>100</span> 金币</div>"; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType } documentAttributes:nil error:nil];_contentLabel.attributedText = attributedString;
>如何让Label等控件同时支持HTML代码和行间距?
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:[_open_bonus_article dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType } documentAttributes:nil error:nil]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];[paragraphStyle setLineSpacing:12]; //调整行间距 [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attributedString length])]; _detailLabel.attributedText = attributedString;[_detailLabel sizeToFit];
链接:http://www.jianshu.com/p/02588a132e22
相关文章推荐
- 在Silverlight页面里显示HTML的免费控件下载(附使用方法代码)
- 梅花雪日历控件3.0-直接复制代码保存为html格式即可运行
- net控件中数据导到Excel的格式 首先,我们了解一下excel从web页面上导出的原理。当我们把这些数据发送到客户端时,我们想让客户端程序(浏览器)以excel的格式读取它,所以把mime类型设为:application/vnd.ms-excel,当excel读取文件时会以每个cell的格式呈现数据,如果cell没有规定的格式,则excel会以默认的格式去呈现该cell的数据。这样就给我们提供了自定义数据格式的空间,当然我们必须使用excel支持的格式。下面就列出常用的一些格式: 1) 文本
- 后台C#代码获取html控件的值使用的Request.Form["name"] 中间的那个应该是空间的name 而不是id
- ExtTag,如果你不想写extjs那么麻烦的代码可以尝试使用html方式的方法来创建extjs控件.
- 设计html日期控件(支持日期显示、时间显示、格式定制)
- HTML格式的语法高亮类库代码,内置对C, C++, VBScript, JScript, xml的支持,可扩展,自己添加语法定义。
- 在VS2008中使用C#代码打印 RichTextBox 控件的内容[方法采自微软支持][Part 1]
- 关于使用WinHtmlEditor控件获得html代码加载到wpf中webbrowser控件上乱码问题
- 支持多种视频格式的html网页视频播放器代码
- HTML格式的语法高亮类库代码,内置对C, C++, VBScript, JScript, xml的支持,可扩展,自己添加语法定义。
- Aspose.Words控件支持DOC,OOXML,RTF,HTML,OpenDocument,PDF,XPS,EPUB和其他格式
- C#使用MailAddress类发送html格式邮件的实例代码
- HTML中使用fileUpLoad控件(代码)
- 在VS2008中使用C#代码打印 RichTextBox 控件的内容[方法采自微软支持][Part 2]
- iOS中支持HTML文本的标签控件——MDHTMLLabel
- 在Silverlight页面里显示HTML的免费控件下载(附使用方法代码)
- 使用asp:Literal控件显示Html代码
- iOS - 支持水平 / 垂直显示自动滚动的跑马灯控件 --- SKAutoScrollLabel 的使用和实现
- 支持各种格式的网页播放器控件代码