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

UILabel显示html文本

2016-04-28 11:29 465 查看
有时候后台会返回给我们一串html的字符串,如果想要在label上显示,就需要做以下处理:

    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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: