您的位置:首页 > 产品设计 > UI/UE

iOS UILabel显示HTML文本

2015-10-09 11:58 555 查看
[objc] view
plaincopy





NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";

NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];

myLabel.attributedText = attrStr;

[self.view addSubview:myLabel];

只能在iOS7以后运行
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: