iOS UILabel显示HTML文本

[objc]  view plain copy
  1. NSString * htmlString = @" Some html string \n 13\" color=\"red\">This is some text! ";  
  2. NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];  
  3. UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];  
  4. myLabel.attributedText = attrStr;  
  5. [self.view addSubview:myLabel];  

只能在iOS7以后运行

你可能感兴趣的:(iOS与HTML交互,ios)