自适应UITableView的Cell高度问题
1.自己计算Cell的高度返回:
1>model中计算:
//
// InfoModel.h
// OCDemo
//
// Created by 思 彭 on 16/12/27.
// Copyright © 2016年 思 彭. All rights reserved.
// #import <Foundation/Foundation.h> @interface InfoModel : NSObject @property (nonatomic, copy) NSString *uid;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *desc;
@property (nonatomic, copy) NSString *headImage; @property (nonatomic, assign) CGFloat cellHeight; - (instancetype)initWithDictionary: (NSDictionary *)dic; @end
//
// InfoModel.m
// OCDemo
//
// Created by 思 彭 on 16/12/27.
// Copyright © 2016年 思 彭. All rights reserved.
// #import "InfoModel.h" @implementation InfoModel - (instancetype)initWithDictionary: (NSDictionary *)dic { if (self = [super init]) { self.title = dic[@"title"];
self.headImage = dic[@"img"];
self.desc = dic[@"desc"]; CGSize contentSize = [self.desc boundingRectWithSize:CGSizeMake(K_SCREEN_WIDTH - , ) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:]} context:nil].size;
self.cellHeight = contentSize.height + ;
}
return self;
} @end
2.自定义CellFrame类存储Cell高度:
//
// CellFrame.h
// OCDemo
//
// Created by 思 彭 on 16/12/28.
// Copyright © 2016年 思 彭. All rights reserved.
// #import <Foundation/Foundation.h>
#import "InfoModel.h" @interface CellFrame : NSObject @property (nonatomic, assign) CGRect headImgViewFrame;
@property (nonatomic, assign) CGRect titleLabelFrame;
@property (nonatomic, assign) CGRect contentlabelFrame;
@property (nonatomic, assign) CGFloat cellHeight; @property (nonatomic, strong) InfoModel *model; @end
//
// CellFrame.m
// OCDemo
//
// Created by 思 彭 on 16/12/28.
// Copyright © 2016年 思 彭. All rights reserved.
// #import "CellFrame.h" @implementation CellFrame - (void)setModel:(InfoModel *)model { _model = model;
_headImgViewFrame = CGRectMake(, , , );
CGSize contentSize = [model.desc boundingRectWithSize:CGSizeMake(K_SCREEN_WIDTH - , ) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:]} context:nil].size;
_titleLabelFrame = CGRectMake(CGRectGetMaxX(_headImgViewFrame) + , , K_SCREEN_WIDTH - - , );
_contentlabelFrame = CGRectMake(, CGRectGetMaxY(_headImgViewFrame) + , K_SCREEN_WIDTH - , contentSize.height);
_cellHeight = CGRectGetMaxY(_contentlabelFrame);
} @end
2.使用第三方Masonry自使用行高:
很方便,要求自己把约束要设置完全!!!
自适应UITableView的Cell高度问题的更多相关文章
- UITableView自动计算cell高度并缓存
原文链接:http://www.jianshu.com/p/64f0e1557562 cell高度计算的历史 在iOS8之前,如果UITableViewCell的高度是动态的,如果想要显示正确的话,我 ...
- UITableView和UICollectionView的Cell高度的几种设置方式
UITableViewCell 1.UITableView的Cell高度默认由rowHeight属性指定一个低优先级的隐式约束 2.XIB中可向UITableViewCell的contentView添 ...
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...
- iOS 开发中单元格cell高度自适应
高度自适应分下面两种情况 1.用代码自定义的cell 用代码自定义的cell,cell高度自定义需要我们手动的去计算每个cell的字符串高度.然后返回对应的高度即可. 2.用XIB 或者 StoreB ...
- iOS开发之多种Cell高度自适应实现方案的UI流畅度分析
本篇博客的主题是关于UI操作流畅度优化的一篇博客,我们以TableView中填充多个根据内容自适应高度的Cell来作为本篇博客的使用场景.当然Cell高度的自适应网上的解决方案是铺天盖地呢,今天我们的 ...
- 转:iOS开发之多种Cell高度自适应实现方案的UI流畅度分析
本篇博客的主题是关于UI操作流畅度优化的一篇博客,我们以TableView中填充多个根据内容自适应高度的Cell来作为本篇博客的使用场景.当然Cell高度的自适应网上的解决方案是铺天盖地呢,今天我们的 ...
- UITableView自定义Cell中,纯代码编程动态获取高度
在UITableView获取高度的代理方法中,经常需要根据实际的模型重新计算每个Cell的高度.直接的做法是在该代理方法中,直接根据模型来返回行高:另 [1]-(CGFloat)tableView:( ...
- 几种设置UITableView的cell动态高度的方法
1.UITableView加载的顺序是先得到表的行的高度,也就是先调用heightForRowAtIndexPath方法,然后再调用cellForRowAtIndexPath,所以我们有两个办法实现自 ...
- UITableView cell 半透明效果,改变cell高度时背景不闪的解决方法
如果直接指定cell.backgroundColor = = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 ...
随机推荐
- Arch Linux PDF格式文件无法显示中文
From: http://blog.sina.com.cn/s/blog_5e54bc6801012gfg.html $ sudo pacman -S poppler-data
- U盘centos7系统安装http://www.augsky.com/599.html
修改第二步中按TAB键出来的命令 这里注意了:网上很多文章都说这一步改成">vmlinuz initrd=initrd.img inst.stage2=hd:/dev/sdbquiet ...
- IntelliJ IDEA 中文乱码问题解决办法
自己最近在使用IntelliJ IDEA,发现总是出现中文乱码的问题,在网上找了很多教程,发现真是“天下文章一大抄”.还不如自己动手试着解决一下. 1.编辑器以及调试信息中文乱码问题 解决方案: 选择 ...
- oracle计算是否是同一周
函数已经解决跨年问题 select to_char(date'2016-12-31','iW') from dual; select to_char(date'2017-01-01','iW') fr ...
- linux 进程的创建
1. 进程号: 每个进程在被初始化的时候,系统都会为其分配一个唯一标识的进程id,称为进程号: 进程号的类型为pid_t,通过getpid()和getppid()可以获取当前进程号和当前进程的父进程的 ...
- sql中limit使用方法
此处以mysql为例,但是我相信物以变通在oracle上也一定适用 下面是几种limit的方法:原则看看下面几个例子应该就懂了 在数据库中很多地方都会用到,比如当你数据库查询记录有几万.几十万时使用l ...
- 简单的 Promise 实现
参考 http://www.tuicool.com/articles/RzQRV3 var PENDING = undefined, FULLFILLED = 1, REJECTED = 2; var ...
- Cacti修改采集精度为1分钟
前言: 基础知识:建议先了解一下 rrdtool 及 rrd 数据库的工作原理,参考阅读<rrdtool学习笔记> cacti主要使用了rrdtool这个工具来绘图,所以看上去比zabbi ...
- python之GUI编程(二)win10 64位 pygame的安装
pygame的下载网址: http://www.pygame.org/download.shtml 我下载了第一个 很显然,安装的时候出现了如图中的尴尬,更改了安装目录后,在Python shell中 ...
- mybatis - resultMap
resultMap有比较强大的自动映射,下面是摘自mybatis中文官网的的片段: 当自动映射查询结果时,MyBatis会获取sql返回的列名并在java类中查找相同名字的属性(忽略大小写). 这意味 ...