iOS UILable自适应撑高即UITableViewCell的高度自适应改变
来源:互联网 发布:大金焓湿图计算软件 编辑:程序博客网 时间:2024/05/16 06:50
UILable的自适应撑高,好久就使用这个相关的技术,就是一直没有时间总结这个知识点,今天终于有时间总结这一块的内容了,lable的自适应撑高是根据计算,将lable相关的内容进行填充的过程,这个过程我封装了一个方法,只要UILable调用即可,代码段如下:
#pragma mark - lable自适应高度的计算- (CGRect)adaptiveLabelFrame:(UILabel *)label font:(UIFont *)font{ CGSize size =CGSizeMake(300,20000); CGSize actualsize; if (IS_IOS7) { // 获取当前文本的属性 NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,nil]; //ios7方法,获取文本需要的size,限制宽度 actualsize =[label.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:tdic context:nil].size; } else { actualsize= [label.text sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping]; } CGRect rect = label.frame; rect.size = actualsize; return rect;}
创建一个Lable仅仅需要将此lable调用这个方法即可,Lable的创建如下代码段:
_showContentLable = [[UILabel alloc] initWithFrame:self.bounds]; _showContentLable.numberOfLines = 0; _showContentLable.font = [UIFont fontWithName:@"Arial" size:12]; _showContentLable.text = @"中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则国强中国强则"; _showContentLable.backgroundColor = [UIColor whiteColor]; self.lableAdativeHeight = [self adaptiveLabelFrame:_showContentLable font:_showContentLable.font]; _showContentLable.frame = self.lableAdativeHeight; NSLog(@"---%f,%f,%f,%f---",self.lableAdativeHeight.origin.x,self.lableAdativeHeight.origin.y,self.lableAdativeHeight.size.width,self.lableAdativeHeight.size.height); [self.contentView addSubview:_showContentLable];
最后实现效果如下图:
OK,自适应撑高就是如此简单。。。。。。。。。
0 0
- iOS UILable自适应撑高即UITableViewCell的高度自适应改变
- iOS UILable自适应高度
- iOS 下,UILable自适应高度的方法
- iOS - UITableViewCell自适应高度
- UITableViewCell 高度的自适应
- UITableViewCell的高度自适应
- iOS开发: UITableViewCell的自适应高度
- [ios]UITableViewCell自适应高度 【转】
- iOS UILable根据文本内容自适应高度
- 【代码笔记】iOS-UILable高度自适应(sizeWithFont)
- UILable自适应文字高度
- iOS 改变TableHeadView的高度,tableView自适应
- UILable的自动换行和自适应高度
- iOS编程------自定义UITableViewCell / cell自适应高度
- iOS 轻松实现UITableViewCell 自适应高度
- iOS 客户端学习-UITableViewCell高度自适应
- iOS UITableViewCell嵌套UIWebView 自适应高度
- iOS UITableViewCell自适应高度单元格问题?
- 【转】献给写作者的 Markdown 新手指南
- 火狐上调试
- iOS技术浅谈之第一篇 (前言篇)
- leetcode Remove DUplicates from Sorted List
- Oracle Function ---- 函数
- iOS UILable自适应撑高即UITableViewCell的高度自适应改变
- 六步实现Rest风格的API
- Linux netstat命令详解
- 怎么才能把PDF文件转换成PPT格式
- java转换json需要导入的jar包,org/apache/commons/lang/exception/NestableRuntimeException
- 【SICP练习】84 练习2.56
- android SeekBar 的基本应用和自定义SeekBar
- php统计网站/html页面浏览访问次数程序
- Java线程状态