求教,如何让Label上显示HTML的字符串
发布网友
发布时间:2022-04-21 12:46
我来回答
共1个回答
热心网友
时间:2022-04-21 14:15
NSString * htmlString = _dataDic[@"description"];
NSAttributedString * attrStr = [[NSAttributedString alloc]initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
_xiangMuLabel.attributedText = attrStr;
NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:10.0f]};
CGSize size = [_xiangMuLabel.text boundingRectWithSize:CGSizeMake(_xiangMuLabel.frame.size.width, MAXFLOAT) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
//根据计算结果重新设置UILabel的尺寸
[_xiangMuLabel setFrame:CGRectMake(WIDTH*0.09, HEIGHT*0.507*0.059, WIDTH*0.819, size.height)];