原生的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 ...
随机推荐
- break,continue,return 区别
using System;using System.Collections.Generic;using System.Text; namespace breakcontinue_test{ cl ...
- iOS 面试题 1
1. 简述OC中内存管理机制.与retain配对使用的方法是dealloc还是release,为什么?需要与alloc配对使用的方法是dealloc还是release,为什么?readwrite ...
- /调整button的title的位置
[bottomButton setTitleEdgeInsets:UIEdgeInsetsMake(10, -190, 10, 44)]; //上左下右 ||button.co ...
- C++服务器设计(四):超时管理机制设计
前四章介绍了系统层的设计,从这一章开始进入服务层的设计. 连接断开 在常见的服务器场景中,客户端断开连接的方式为被动关闭.即作为客户端请求完服务器的服务后,选择主动关闭同服务器的连接.在服务器的角度看 ...
- Linux中Firefox——Httpfox插件安装及使用
Httpfox插件安装步骤: 1.打开firefox浏览器,点击左上方"工具"中的"附加组件" 2.在弹出页中搜索"Httpfox",点击下 ...
- Nvidia CUDA 6 Installed In Ubuntu 12.04
环境:ubuntu 12.04 (x64) 如果不能够 service lightdm stop,显示:unknown service 或者其他的 sudo /etc/init.d/lightdm r ...
- cherry-pick,revert和rebase使用的3-way合并策略
git中的cherry-pick,revert和rebase都使用的是3-way合并策略,下面就来看看这3个方法使用的merge-base,ours和theirs分别是什么. cherry-pick ...
- 评论PK投票功能的手机版
ajax投票.点赞.回复,投票后自动转到查看投票结果,投票结果进度条动画显示 地址:http://files.cnblogs.com/files/macliu/hyw_wap.rar 效果图: 首页:
- ASP.NET Ajax In Action!
创建XMLHTTPRequest 代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeH ...
- Qt之HTTPS登录(集成QNetworkAccessManager提前修改QSslConfiguration,然后post)
简述 HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版.即HTTP ...