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;
}
<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;
}
相关文章推荐
- java集合类深入分析之Queue篇
- 63. Unique Paths II
- runtime-运行时动态添加占位文字颜色-UITextField
- "mkimage" command not found - U-Boot images will not be built
- NGUI
- 无网或断网提示,自定义界面(UIView分类,使用方便)
- easyui-datagrid控件保存选中项,每次打开页面上次被选中的行前面都被勾选
- automaticallyAdjustsScrollViewInsets和edgesForExtendedLayout和extendedLayoutIncludesOpaqueBars
- 集成容联:Warning! ivar size mismatch in PSUICollectionView_ - can't change the superclass.解决办法
- HDU 1005 Number Sequence
- 【Arduino官方教程第一辑】示例程序 3-7 信号平滑
- 【C#枚举】根据EnumName获取Value
- deque
- iOS导航栏自动隐藏和显示属性,UINavigationController属性
- 347 Top K Frequent Elements
- easyui from 缓存问题处理
- UIAlertController 使用
- Android关于buildToolVersion与CompileSdkVersion的区别
- 62. Unique Paths
- dequeueReusableCellWithIdentifier 总是返回nil