iOS 另一种富文本转化方式 html转为富文本
直接用html转化为iOS的富文本。
代码如下:
-(void)demo2
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 300, 300)];
label.numberOfLine = 0;
[self.view addSubview:label];
NSString *content = @"\<p style=\"font-family:verdana;color:red\"> This text <a style=\"font-family:times;color:green;font-size:30px\">This text is in Times and green</a>is in Verdana and red</p><p style=\"font-size:50px\">This text is 50 pixels high</p>";
NSData *data = [content dataUsingEncoding:NSUnicodeStringEncoding];
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSAttributedString *html = [[NSAttributedString alloc]initWithData:data
options:options
documentAttributes:nil
error:nil];
label.attributedText = html;
}