//// 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