UILabel显示HTML字符串

2017-12-29  本文已影响15人  Fisher123

str是要显示的HTML字符串,UILabel支持显示HTML显示

NSString *str = [timetable.content copy]; 
if(str.length>0){
    NSMutableAttributedString *attrString =
    [[NSMutableAttributedString alloc] initWithData:[str
    dataUsingEncoding:NSUnicodeStringEncoding]
    options:@{NSDocumentTypeDocumentAttribute:
    NSHTMLTextDocumentType} documentAttributes:nil error:nil];
  [attrString addAttribute:NSFontAttributeName value:[UIFont
    systemFontOfSize:16] range:NSMakeRange(0, attrString.length)];
  self.contentLabel.attributedText = attrString;
}

上一篇下一篇

猜你喜欢

热点阅读