UILabel展示html富文本

来源:互联网 发布:淘宝网迪奥香水 编辑:程序博客网 时间:2024/04/30 05:24



    UILabel展示html文本

   

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

    NSAttributedString * attrStr = [[NSAttributedStringalloc]initWithData:[htmlStringdataUsingEncoding:NSUnicodeStringEncoding]options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType }documentAttributes:nilerror:nil];

   UILabel * myLabel = [[UILabelalloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

    myLabel.attributedText = attrStr;

    [self.viewaddSubview:myLabel];


0 0