iOS UILable 加载 html

NSString *str0 = @"

<span style="line-height:2;font-size:14px;">&nbsp; &nbsp; &nbsp; “月月盈产品资金用于国有企业、大型贸易企业、准上市公司在国内外采购有色金属、化工原料、汽车配件、针织纺品、橡塑制品等大宗商品。该产品经佰亿猫多重风控保障,严格对借款人的资产规模与负债结构进行审核,物权与资金双重掌控。借款人资金需求合理,经营状况良好,银行信用证结算,资金流向明确可查。</span><br />

<div>

<br />

</div>

"


 //加载html

    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[str0 dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

    NSString *str = attrStr.string;

    CGRect rect =  [self rectHeightWithStr:str AndFont:13 WithStrWidth:KScreen_Width - 20];

    _titleLabel.frame = CGRectMake(10, 0, KScreen_Width - 20, rect.size.height);

    _titleLabel.height = rect.size.height+ 10;

    _titleLabel.text = str;


//根据文本的宽度 字体的大小来获取文本的高度

- (CGRect)rectHeightWithStr:(NSString *)str AndFont:(CGFloat)fontFloat WithStrWidth:(CGFloat)width

{

    CGRect fcRect = [str boundingRectWithSize:CGSizeMake(width, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontFloat]} context:nil];

    return fcRect;

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值