UILabel加载html文本

2017-11-06  本文已影响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];
上一篇下一篇

猜你喜欢

热点阅读