原生的UITableViewCell高度自适应,textLabel自动换行显示
/*
* 设置子项cell
**/
- (UITableViewCell *)getChildCell:(UITableView *)tableView and:(NSIndexPath *)indexPath {
CourseWareModel * childModel = [self isChild:indexPath];
UITableViewCell * cell;
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
//设置Cell不可点击
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = childModel.courseWareName;
cell.textLabel.font = [UIFont systemFontOfSize:];
cell.textLabel.textColor = [PlistResourceUtil getColor:@"courselist_name"];
cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
//显示最右边的箭头
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //获得当前cell高度
CGRect frame = [cell frame];
//设置label的最大行数
cell.textLabel.numberOfLines = 10;
CGSize size = CGSizeMake(300, 1000);
CGSize labelSize = [cell.textLabel.text sizeWithFont:cell.textLabel.font constrainedToSize:size lineBreakMode:NSLineBreakByClipping];
cell.textLabel.frame = CGRectMake(cell.textLabel.frame.origin.x, cell.textLabel.frame.origin.y,labelSize.width, labelSize.height);
//计算出自适应的高度
frame.size.height = labelSize.height+16;
cell.frame = frame; return cell;
}
然后在heightForRowAtIndexPath方法中返回cell的height
#pragma mark - 大小样式设置
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self isGroup:indexPath]) {
CourseGroupCell * cell = [self getGroupCell:tableView and:indexPath];
CGFloat height = cell.frame.size.height;
return height;
// return 48; // 分组高
}
UITableViewCell * cell = [self getChildCell:tableView and:indexPath];
CGFloat height = cell.frame.size.height;
return height;
// return 40; // 行高
}
原生的UITableViewCell高度自适应,textLabel自动换行显示的更多相关文章
- uitableviewcell高度自适应笔记
今天看了几篇uitableviewcell高度自适应的文章,大体分为两种方式. 第一种方式,cell里面有label,在cellforrow绘制的时候计算Label的可能高度,并且在此时重新计算cel ...
- UITableViewCell高度自适应探索--AutoLayout结合Frame
UITableViewCell高度自适应探索--UITableView+FDTemplateLayoutCell地址: http://www.jianshu.com/p/7839e3a273a6UIT ...
- UITableViewCell高度自适应的关键点
iOS开发中对于UITableViewCell高度自适应的文章已经很多很多,但如果cell内容比较复杂,刚使用autolayout配置自使用时还是总不能一次性成功. KEY POINT 这里只说设置的 ...
- UITableViewCell 高度自适应
UITableViewCell 高度自适应一直是我们做动态Cell高度时遇到的最烦躁的问题,Cell动态高度计算可以去看看sunny的这篇文章介绍,今天主要和大家分享下我在使用systemLayout ...
- 第二篇、为UITableViewCell 高度自适应加速 缓存cell的高度
通过NSCache缓存已经算好的行高 @interface ZHCellHeightCalculator : NSObject //系统计算高度后缓存进cache -(void)setHeight:( ...
- UITableViewCell 高度计算从混沌初始到天地交泰
[原创]UITableViewCell 高度计算从混沌初始到天地交泰 本文主要基予iOS UITableViewCell 高度自适应计算问题展开陈述,废话少说直入正题: UITableView控件可能 ...
- css实现div中图片高度自适应并与父级div宽度一致
需求:1.父级div不设置高度 2.图片高度自适应,并且显示为正方形: 以前遇到列表中图片高度必须和父级宽度相同,并且需要为正方形的时候,最开始的方法是定死图片高度,这样会导致不同分辨率下图片会压缩, ...
- autolayout 高度自适应
https://lvwenhan.com/ios/449.html #import "ViewController.h" #import "MyTableViewCell ...
- css 实现文字自动换行切同行元素高度自适应
1.实现div行内布局所有行跟随最大高度自适应 html代码样例: <div class="row-single"> <div class="colsp ...
随机推荐
- 改进的简单Tooltips显示
使用js简单改进了Tooltips的显示效果,可进一步使用CSS对改进的Tooltips进行美化. 前台布局代码: <asp:Panel ID="Panel1" runat= ...
- SQL Server根据列名查表
select a.name, b.name from syscolumns a, sysobjects b where a.name = 'XXXX' and a.id = b.id and b.xt ...
- ssh localhost无密码登录设置
亲测... ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys ...
- 使用Apache JMeter进行SQL优化性能测试
一. 前言 最近在公司里做性能测试,对于一张大概400万数据的表,进行全表扫描往往会比较费时,更不要说有若干这样的表格级联进行检索了.为了能够在不影响生产环境的前提下进行SQL的性能优化,需要首先利用 ...
- spring mvc ajax
<%@ page contentType="text/html;charset=UTF-8" %> <%@ include file="/WEB-INF ...
- Window Linux下实现指定目录内文件变更的监控方法
转自:http://qbaok.blog.163.com/blog/static/10129265201112302014782/ 对于监控指定目录内文件变更,window 系统提供了两个未公开API ...
- 每天一点css3聚沙成塔(一):transition
transition 语法: transition:[ transition-property ] || [ transition-duration ] || [ transition-timing- ...
- awk之7 常用函数的解析
1.区域获取 substr(区域f,起始位置n1,获取范围n2) 解析:获取某个区域f内,从起始位置n1开始算起的n2个字符组成的字符串.如果n2不存在,则返回从n1开始到区域结束的内容. 例子:获取 ...
- [TYVJ] P1030 乳草的入侵
乳草的入侵 背景 Background USACO OCT09 6TH 描述 Description Farmer John一直努力让他的草地充满鲜美多汁的而又健康的牧草.可惜天不从人愿,他在植物 ...
- javascript string对象的属性与方法
一 创建string对象 new string('string'); 更直接的定义方法是var str = 'string'; 二 string属性 1.constructor 2.lenght 字符 ...