iOS UILabel显示HTML文本
2015-10-09 11:58
555 查看
[objc] view
plaincopy
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];
myLabel.attributedText = attrStr;
[self.view addSubview:myLabel];
只能在iOS7以后运行
plaincopy
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];
myLabel.attributedText = attrStr;
[self.view addSubview:myLabel];
只能在iOS7以后运行
相关文章推荐
- 解决Django 提交表单时403错误:CSRF verification failed. Request
- UIView的layoutSubviews和drawRect方法何时调用
- 探究UIImagePickerController
- 循环队列_queue
- java中List、Map、Set、Collection、Stack、Queue等的使用
- Fourier Transform Intro - Oscillation frequency vs Angular frequency Expression
- poj 3498 March of the Penguins(最大流+拆点)
- Leetcode89: Unique Paths
- StringBuilder、StringBuffer和String三者的联系和区别
- UISegmentedControl的基本用法
- iOS开发UI篇—UITabBarController简单介绍
- uitableview顶部多出20距离, UIScollView顶部多出64距离
- [Leetcode] Longest Consecutive Sequence
- request和response
- 使用Sequel Pro通过ssh远程连接MySQL出错:The SSH Tunnel has unexpectedly closed
- Jenkins系列之—17 一个完整的JENKINS下的ANT BUILD.XML文件
- Xcode Build Search Paths设置
- Android Uevent 分析,从kernel到framework
- 删除flash builder(4.7)多余的工作空间
- iOS7 物理动力学UIDynamic