TextView加载带有html标签的字符串
2017-09-19 本文已影响8人
小小纳兰
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 100, 260, 200)];
NSString *param = @"
This is
a para
graph with line breaks
";
NSAttributedString *attributedString = [[NSAttributedStringalloc] initWithData:[param dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}documentAttributes:nilerror:nil];
textView.attributedText = attributedString;
[self.view addSubview:textView];