原生的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 ...
随机推荐
- 使用HttpClient发送GET请求
HttpRequestMessage http_req_msg = new HttpRequestMessage(); http_req_msg.Method = HttpMethod.Get; ht ...
- PHP学习笔记二十五【类的继承】
<?php //定义父类 class Stu{ public $name; protected $age; protected $grade; private $address;//私有变量不会 ...
- Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
I have installed a Web application on IIS 7.0 windows server 2008 R2 64 bit OS I am refering a oracl ...
- weblogic开机启动脚本
1.在/home/bea/startBeaAll目录内创建一个startBeaAll.sh文件,加入如下内容(把相应目录与命令修改即可,红字部分为修改地方): #!/bin/sh echo " ...
- iPhone6设计自适应布局
http://www.devtalking.com/articles/adaptive-layout-for-iphone6-1/ http://www.devtalking.com/articles ...
- C++中const
[const] 0.普通const对象定义在栈空间中 { ; ; cout << &a << ' ' << &b; } Result: 0x22ab ...
- JAVA操作properties文件
va中的properties文件是一种配置文件,主要用于表达配置信息,文件类型为*.properties,格式为文本文件,文件的内容是格式是"键=值"的格式,在properties ...
- 【Python网络编程】多线程聊天软件程序
课程设计的时候制作的多线程聊天软件程序 基于python3.4.3 import socket import pickle import threading import tkinter import ...
- 我和Python的第一次亲密接触 - 零基础入门学习Python001
我和Python的第一次亲密接触 让编程改变世界 Change the world by program 小甲鱼经常说,学习一门编程语言就是要深入其中,要把编程语言想象为你的女朋友你的情人,这样你学习 ...
- c链表结点的删除和添加
#include<stdio.h> #include<stdlib.h> typedef char datetype;/*定义新的数据类型名*/ typedef struct ...