美文网首页
UILabel加载html文本

UILabel加载html文本

作者: 冉俊 | 来源:发表于2017-11-06 13:57 被阅读18次

UILabel加载html文本

 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:CGRectMake(0, 100, 200, 50)];
   
myLabel.attributedText = attrStr;
   
myLabel.backgroundColor = [UIColor greenColor];
 
  [self.view addSubview:myLabel];

相关文章

网友评论

      本文标题:UILabel加载html文本

      本文链接:https://www.haomeiwen.com/subject/hjllmxtx.html