原生的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 ...
随机推荐
- SQL中的delete和TRUNCATE的用法
TRUNCATE TABLE 表名 删除表中的所有行,而不记录单个行删除操作. 语法 TRUNCATE TABLE name 参数 name 是要截断的表的名称或要删除其全部行的表的名称. 注释 TR ...
- POJ 1269 - Intersecting Lines 直线与直线相交
题意: 判断直线间位置关系: 相交,平行,重合 include <iostream> #include <cstdio> using namespace std; str ...
- CDZSC_2015寒假新人(2)——数学 H
H - H Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- (原+转)pycharm中使用caffe
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5896446.html 参考网址: http://www.th7.cn/Program/Python/2 ...
- (转)eclipse 代码自动补全
转自:http://blog.csdn.net/yushuwai2010/article/details/11856129 一般默认情况下,Eclipse的代码提示功能是比MicrosoftVisua ...
- Image的Stride
参看下面链接:http://msdn.microsoft.com/en-us/library/aa473780
- MySql学习之数据库管理
一步一步学习mysql数据,首先是mysql数据的管理操作. 1. 创建数据库 命令格式:create database [if not exists] database_name. 实际的使用过程中 ...
- apche commons项目简介
1.apche commons项目封装了日常开发中经常使用的功能,如io, String等. http://commons.apache.org/ Apache Commons项目的由三部分组成: T ...
- jquery find()和filter()的区别
在写js查找当前标签下某一子元素的子元素集合时,用到了此方法 $(".flyout-trigger").mouseover(function(){ var maxnum=$(thi ...
- https://github.com/aptana/studio3/releases aptana
https://github.com/aptana/studio3/releases aptana