码迷,mamicode.com
首页 > 移动开发 > 详细

iOS UIText 或 UILabel 显示 HTML 并正确选用编码

时间:2014-09-10 17:37:20      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:des   style   color   os   io   sp   html   on   c   

有的时候我们可能会选用 UIText 或 UILabel 来显示 HTML 代格式的文字。

 

NSAttributedString *html = [[NSAttributedString allocinitWithData:[NSLocalizedString(@"comment", nil) dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }documentAttributes:nil error:nil];

用 UICode 这种编码方式很重要。它可以显示法语等语言的特殊字符。 比如 UTF-8就不能。Latin1,2 编码方式可以只能显示部分特殊字符。比如 

“œ” 就显示不出来。

iOS UIText 或 UILabel 显示 HTML 并正确选用编码

标签:des   style   color   os   io   sp   html   on   c   

原文地址:http://www.cnblogs.com/davesuen/p/3964747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!