【版本适配】iOS中文本的自适应高度
2014-07-08 21:42
288 查看
//文字高度
+ (float)height:(NSString *)lab
{
#ifdef __IPHONE_7_0
NSDictionary * dic = [NSDictionary
dictionaryWithObjectsAndKeys:[UIFont
systemFontOfSize:
K_FONT_SIZE],NSFontAttributeName,
nil];
if ([[[UIDevice
currentDevice]systemVersion]floatValue]>=7.0) {
CGRect rect = [lab
boundingRectWithSize:CGSizeMake(K_INTRODUCE_LABLE_WIDTH,
0) options:NSStringDrawingUsesLineFragmentOrigin
attributes:dic context:nil];
if ([lab isEqualToString:@""]) {
rect.size.height =
0;
}
return rect.size.height;
}
else
{
CGSize rect = [lab
sizeWithFont:[UIFont
systemFontOfSize:K_FONT_SIZE]
constrainedToSize:CGSizeMake(220,2000)
lineBreakMode:NSLineBreakByTruncatingHead];
if ([lab isEqualToString:@""]) {
rect.height =
0;
}
return rect.height;
}
#endif
}
- (void)setCellVal:(NSString *)cellVal
{
if (_cellVal != cellVal) {
[_cellVal
release];
_cellVal = [cellVal
retain];
}
self.cellLabel.text = cellVal;
#ifdef __IPHONE_7_0
//计算文本在限定范围内的高度
NSDictionary * dic = [NSDictionary
dictionaryWithObjectsAndKeys:[UIFont
systemFontOfSize:K_FONT_SIZE],
NSFontAttributeName, nil];
if ([[[UIDevice
currentDevice]systemVersion]floatValue]>=7.0) {
CGRect rect = [_cellLabel.text
boundingRectWithSize:CGSizeMake(K_INTRODUCE_LABLE_WIDTH,
0) options:NSStringDrawingUsesLineFragmentOrigin
attributes:dic context:nil];
_cellLabel.frame =
CGRectMake(_cellLabel.left,
_cellLabel.top,
_cellLabel.width, rect.size.height);
}
else
if ([[[UIDevice
currentDevice]systemVersion]floatValue] <
7.0){
CGSize rect = [_cellLabel.text
sizeWithFont:[UIFont
systemFontOfSize:K_FONT_SIZE]
constrainedToSize:CGSizeMake(220,2000)
lineBreakMode:NSLineBreakByTruncatingHead];
_cellLabel.frame =
CGRectMake(_cellLabel.left,
_cellLabel.top,
_cellLabel.width, rect.height);
}
#endif
}
+ (float)height:(NSString *)lab
{
#ifdef __IPHONE_7_0
NSDictionary * dic = [NSDictionary
dictionaryWithObjectsAndKeys:[UIFont
systemFontOfSize:
K_FONT_SIZE],NSFontAttributeName,
nil];
if ([[[UIDevice
currentDevice]systemVersion]floatValue]>=7.0) {
CGRect rect = [lab
boundingRectWithSize:CGSizeMake(K_INTRODUCE_LABLE_WIDTH,
0) options:NSStringDrawingUsesLineFragmentOrigin
attributes:dic context:nil];
if ([lab isEqualToString:@""]) {
rect.size.height =
0;
}
return rect.size.height;
}
else
{
CGSize rect = [lab
sizeWithFont:[UIFont
systemFontOfSize:K_FONT_SIZE]
constrainedToSize:CGSizeMake(220,2000)
lineBreakMode:NSLineBreakByTruncatingHead];
if ([lab isEqualToString:@""]) {
rect.height =
0;
}
return rect.height;
}
#endif
}
- (void)setCellVal:(NSString *)cellVal
{
if (_cellVal != cellVal) {
[_cellVal
release];
_cellVal = [cellVal
retain];
}
self.cellLabel.text = cellVal;
#ifdef __IPHONE_7_0
//计算文本在限定范围内的高度
NSDictionary * dic = [NSDictionary
dictionaryWithObjectsAndKeys:[UIFont
systemFontOfSize:K_FONT_SIZE],
NSFontAttributeName, nil];
if ([[[UIDevice
currentDevice]systemVersion]floatValue]>=7.0) {
CGRect rect = [_cellLabel.text
boundingRectWithSize:CGSizeMake(K_INTRODUCE_LABLE_WIDTH,
0) options:NSStringDrawingUsesLineFragmentOrigin
attributes:dic context:nil];
_cellLabel.frame =
CGRectMake(_cellLabel.left,
_cellLabel.top,
_cellLabel.width, rect.size.height);
}
else
if ([[[UIDevice
currentDevice]systemVersion]floatValue] <
7.0){
CGSize rect = [_cellLabel.text
sizeWithFont:[UIFont
systemFontOfSize:K_FONT_SIZE]
constrainedToSize:CGSizeMake(220,2000)
lineBreakMode:NSLineBreakByTruncatingHead];
_cellLabel.frame =
CGRectMake(_cellLabel.left,
_cellLabel.top,
_cellLabel.width, rect.height);
}
#endif
}
相关文章推荐
- 每天学一点flex(3) :文本自适应高度在不同版本的sdk是否存在差异?
- iOS中文本自适应高度显示完所有文字
- IOS动态获取文本的高度--自适应文本宽度、高度Textview
- iOS UILabel富文本自适应高度
- Ios UILabel 自适应 文本高度
- iOS Label文本自适应高度
- iOS学习笔记 自定义cell并且文本自适应高度
- 文本自适应高度(含适配iOS7)
- 每天学一点flex(3) :文本自适应高度在不同版本的sdk是否存在差异?
- IOS 文本高度自适应变化实现实例
- IOS 开发中 TableView的文本Cell高度的自适应,UILabel自动换行适应
- iOS NSString 文本不同的颜色 标题+文本字体大小 行间距/删除不需要的字符 /以及自适应高度
- iOS开发笔记--UILabel和UITextView自适应文本高度代码
- iOS UILable根据文本内容自适应高度
- UILabel的自适应高度iOS7.0以上版本
- iOS开发笔记--UILabel和UITextView自适应文本高度代码
- IOS动态获取字符串NSString的长宽--自适应文本宽度、高度
- iOS label显示HTML(富文本)代码 (解析)并实现高度自适应
- 设置代码ios中根据文本设置label高度设置代码
- UITextView使用 sizeWithFont:constrainedToSize:lineBreakMode:计算自适应文本高度