UILabel顯示html文本

[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";  
  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以後運行
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章