您的位置:首页 > 产品设计 > UI/UE

iOS UILable 加载 html

2016-05-11 16:21 477 查看
NSString *str0 = @"

<span style="line-height:2;font-size:14px;">      “月月盈”产品资金用于国有企业、大型贸易企业、准上市公司在国内外采购有色金属、化工原料、汽车配件、针织纺品、橡塑制品等大宗商品。该产品经佰亿猫多重风控保障,严格对借款人的资产规模与负债结构进行审核,物权与资金双重掌控。借款人资金需求合理,经营状况良好,银行信用证结算,资金流向明确可查。</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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: