如何加载html格式的文本
来源:互联网 发布:网络说唱歌手皇甫 编辑:程序博客网 时间:2024/05/21 11:14
1.使用一般的控件(比如:UILabel、UITextView)加载HTML
// 使用NSMutableAttributedString来转换HTML文本NSString *htmlStr = @"<p>易微行用户\r</p><p>demo测试用户协议\r</p><p>公司地址\r</p><p>联系电话\r</p><p>电子邮件</p>";NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithData:[htmlStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];[attStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} range:NSMakeRange(0, attStr.length)];UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-self.navigationController.navigationBar.frame.origin.y-self.navigationController.navigationBar.frame.size.height)];textView.showsVerticalScrollIndicator = NO;textView.editable = NO;textView.attributedText = attStr;[self.view addSubview:textView];
2.使用UIWebView加载HTML
NSString *htmlStr = @"<p>易微行用户\r</p><p>demo测试用户协议\r</p><p>公司地址\r</p><p>联系电话\r</p><p>电子邮件</p>";UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64)];webView.userInteractionEnabled = NO;// 这个方法需要将httml文件读取为字符串,其中baseURL是我们自己设置的一个路径,用于寻找html文件中引用的图片等素材[webView loadHTMLString:htmlStr baseURL:nil];[self.view addSubview:webView];
结果:
0 0
- 如何加载html格式的文本
- webview加载html格式的文本
- webview加载html格式的文本出现乱码
- 关于如何显示 html 格式的文本内容
- 在Flash中利用Actionscript在动态文本框中加载HTML格式的文本
- 网页大文本文件的在线加载预览,txt,xml,html等纯文本格式
- 在Flash动态文本框中加载HTML格式文本
- 创建纯文本、HTML格式的邮件
- html的基础标签,文本格式,链接
- Qt处理HTML格式文本的方法
- HTML(格式,文本标签)
- HTML文本格式
- HTML(格式,文本标签)
- 如何将HTML转换为纯文本格式Text
- 将html格式的内容转换成纯文本格式
- TextView加载html文本
- UILabel加载html文本
- webView加载html格式的字符串
- [生存志] 第50节 七穆掌郑国
- 使用freenom注册免费顶级域名并在梅林上使用DDNS
- XStream解析xml为bean时,避免xml出现多余字段报错
- leetcode.(53).205. Isomorphic Strings
- Android Studio Failed to crunch file
- 如何加载html格式的文本
- redis基础之HyperLogLog数据结构
- Xcode 8.1 Create NSManagedObject Subclass 编译错误
- UDP接收和发送线程 实际应用案例
- cocos2d js 网络通信相关信息
- 通过阿里云域名动态解析 IP 地址
- 感知器基础
- Android TV Launcher开源项目
- Intellij快捷键