iOS 显示HTML文本
2016-04-25 13:40
471 查看
1、用webView显示
2、用Label显示
-(void)loadWebViewString:(NSString *)loadString { NSString *content = [[NSString alloc] init]; if (loadString == nil || loadString == NULL) { content =@""; }else content =[NSString stringWithFormat: @"<html>" "<style type=\"text/css\">" "<!--" "body{font-size:12pt;line-height:20pt;}" "-->" "</style>" "<body>" "%@" "</body>" "</html>" , loadString]; [_webView loadHTMLString:content baseURL:nil]; }
2、用Label显示
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];
相关文章推荐
- iOS App中UILabel的自定义及在Auto Layout中的使用
- IOS 7.1 兼容性bug 问题,UIButton,UILabel ...
- UILabel的学习
- UILabel显示HTML
- UILabel
- iOS控件--UILabel
- ULabel显示1.n行文字特效,特效
- [Swift]UIKit学习之UILabel的用法
- label指定位置文字属性设置
- 倒计时
- 第一个IOS程序(代码版)
- 'UITextAlignmentCenter' is deprecated: first deprecated in iOS 6.0设置UILabel的居中对齐时出错
- iOS UI三大控件和应用程序启动流程
- 关于UIview UIlabel Unbutton 的一些常用的属性方法(用以优化界面)
- UILabel自动换行,自适应高度
- UILabel 的基本使用和扩展
- 关于UILable自适应数据内容问题
- iOS8.0以上Label的警告处理
- Lesson1 UIWidow,UIView,UILabel的使用
- iOS开发——UILabel自动换行及高度自适应UILabel自动换行及高度自适应