/*
* 设置子项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自动换行显示的更多相关文章

  1. uitableviewcell高度自适应笔记

    今天看了几篇uitableviewcell高度自适应的文章,大体分为两种方式. 第一种方式,cell里面有label,在cellforrow绘制的时候计算Label的可能高度,并且在此时重新计算cel ...

  2. UITableViewCell高度自适应探索--AutoLayout结合Frame

    UITableViewCell高度自适应探索--UITableView+FDTemplateLayoutCell地址: http://www.jianshu.com/p/7839e3a273a6UIT ...

  3. UITableViewCell高度自适应的关键点

    iOS开发中对于UITableViewCell高度自适应的文章已经很多很多,但如果cell内容比较复杂,刚使用autolayout配置自使用时还是总不能一次性成功. KEY POINT 这里只说设置的 ...

  4. UITableViewCell 高度自适应

    UITableViewCell 高度自适应一直是我们做动态Cell高度时遇到的最烦躁的问题,Cell动态高度计算可以去看看sunny的这篇文章介绍,今天主要和大家分享下我在使用systemLayout ...

  5. 第二篇、为UITableViewCell 高度自适应加速 缓存cell的高度

    通过NSCache缓存已经算好的行高 @interface ZHCellHeightCalculator : NSObject //系统计算高度后缓存进cache -(void)setHeight:( ...

  6. UITableViewCell 高度计算从混沌初始到天地交泰

    [原创]UITableViewCell 高度计算从混沌初始到天地交泰 本文主要基予iOS UITableViewCell 高度自适应计算问题展开陈述,废话少说直入正题: UITableView控件可能 ...

  7. css实现div中图片高度自适应并与父级div宽度一致

    需求:1.父级div不设置高度 2.图片高度自适应,并且显示为正方形: 以前遇到列表中图片高度必须和父级宽度相同,并且需要为正方形的时候,最开始的方法是定死图片高度,这样会导致不同分辨率下图片会压缩, ...

  8. autolayout 高度自适应

    https://lvwenhan.com/ios/449.html #import "ViewController.h" #import "MyTableViewCell ...

  9. css 实现文字自动换行切同行元素高度自适应

    1.实现div行内布局所有行跟随最大高度自适应 html代码样例: <div class="row-single"> <div class="colsp ...

随机推荐

  1. 网页body中background在ie中显示不出来

    网页body中background在ie中显示不出来 | 浏览:349 | 更新:2014-03-11 14:03 刚才上班在公司网站上写一个页面,在谷歌浏览器,火狐浏览器里调试完后,一切正常,忽然想 ...

  2. 解决ScrollView嵌套ListView和GridView冲突的方法

    本文摘抄自:http://blog.csdn.net/yuhailong626/article/details/20639217 原文地址:http://blog.csdn.net/yuhailong ...

  3. Eclipse error:Access restriction

    报错:Access restriction: The method decodeBuffer(String) from the type CharacterDecoder is not accessi ...

  4. Oracle自治事务

    定        义: Autonomous transactions are independent transactions that can be called from within anot ...

  5. dispatch_group_t

    最近在写的模块有这样一个问题,要保证所有block里面的东西全都回来之后再执行某一个 例如我要做完所有的数据库操作再刷新界面,数据库的内容很多,所有用到了group  dispatch_group_t ...

  6. javascript延迟加载及异步(defer和async)

    一直以来写代码的时候的常用习惯就是吧所有的js文件直接加载在文档的head标签里面,在写js文件的时候有时候获取一些文件对象的时候为空对象,这是由于文档结构还没有加载完,但是js文件已经加载完.也就是 ...

  7. css 梯形标签页

    html 代码 略 css : nav > a{ position: relative; display: inline_block; padding: .3em 1em 0; } nav &g ...

  8. 写一个Windows上的守护进程(5)文件系统重定向

    写一个Windows上的守护进程(5)文件系统重定向 在Windows上经常操作文件或注册表的同学可能知道,有"文件系统/注册表重定向"这么一回事.大致来说就是32位程序在64位的 ...

  9. 2015.4.2-SQL 简单语句(一)

    1.创建一个student表 create table student_masen( sno char(4) not null primarykey sname nchar(10) not null ...

  10. juqery合成事件toggle方法

    当指定元素被点击时,在两个或多个函数之间轮流切换. 如果规定了两个以上的函数,则 toggle() 方法将切换所有函数.例如,如果存在三个函数,则第一次点击将调用第一个函数,第二次点击调用第二个函数, ...