使用UITextView加載html文本

使用TextView加載html文本的方式,其實很簡單,將正常的字符串轉化成屬性文本即可,然後賦值給TextView相應的屬性,下面直接上代碼


NSString * htmlString = dic[@"txt"];//dic是網絡獲取到的Html文本的字典,txt是html文本對應的鍵
    
    NSAttributedString * attStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    
    self.textview.attributedText = attStr;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章