博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[iOS]如何给Label或者TextView赋HTML数据
阅读量:7087 次
发布时间:2019-06-28

本文共 1104 字,大约阅读时间需要 3 分钟。

////  ViewController.m//  text////  Created by 李东旭 on 16/1/22.//  Copyright © 2016年 李东旭. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.        // 创建textView    UITextView *textV = [[UITextView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 400)];    [self.view addSubview:textV];        // 设置textView边框宽度和颜色    textV.layer.borderWidth = 2.0f;    textV.layer.borderColor = [UIColor blackColor].CGColor;        // 获取html数据    NSString *htmlString = @"

Header

Subheader

Sometext

"; // 利用可变属性字符串来接收html数据 NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil]; // 给textView赋值的时候就得用attributedText来赋了 textV.attributedText = attributedString; }@end

转载于:https://www.cnblogs.com/wangqi1221/p/5240261.html

你可能感兴趣的文章
计算机图形学 补 光线跟踪
查看>>
spring整合logback配置文件
查看>>
captive portal
查看>>
mysql基本数据类型(mysql学习笔记三)
查看>>
Laravel踩坑笔记——illuminate/html被抛弃
查看>>
飞秋命令行
查看>>
做题时一时没想起来的问题总结
查看>>
[转]python-元类
查看>>
复习日记-Listener/filter/servlet3.0/动态代理
查看>>
Win7x64安装了DroidPilot-Win64.exe之后跑不起来 -- 解决办法
查看>>
VS2010 中C++ 和C# 颜色转化
查看>>
java 自带的工具
查看>>
CentOS 7配置MariaDB允许指定IP远程连接数据库
查看>>
计算机基础——指令与程序
查看>>
用三段 140 字符以内的代码生成一张 1024×1024 的图片<转载>
查看>>
HTML CSS
查看>>
sqlserver存储过程中SELECT 与 SET 对变量赋值的区别
查看>>
【分享】开源富文本编辑器之间的较量
查看>>
logback的使用和logback.xml详解
查看>>
Android Studio -- 关联源码
查看>>