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高度问题的更多相关文章

  1. UITableView自动计算cell高度并缓存

    原文链接:http://www.jianshu.com/p/64f0e1557562 cell高度计算的历史 在iOS8之前,如果UITableViewCell的高度是动态的,如果想要显示正确的话,我 ...

  2. UITableView和UICollectionView的Cell高度的几种设置方式

    UITableViewCell 1.UITableView的Cell高度默认由rowHeight属性指定一个低优先级的隐式约束 2.XIB中可向UITableViewCell的contentView添 ...

  3. 使用Autolayout实现UITableView的Cell动态布局和高度动态改变

    本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...

  4. iOS 开发中单元格cell高度自适应

    高度自适应分下面两种情况 1.用代码自定义的cell 用代码自定义的cell,cell高度自定义需要我们手动的去计算每个cell的字符串高度.然后返回对应的高度即可. 2.用XIB 或者 StoreB ...

  5. iOS开发之多种Cell高度自适应实现方案的UI流畅度分析

    本篇博客的主题是关于UI操作流畅度优化的一篇博客,我们以TableView中填充多个根据内容自适应高度的Cell来作为本篇博客的使用场景.当然Cell高度的自适应网上的解决方案是铺天盖地呢,今天我们的 ...

  6. 转:iOS开发之多种Cell高度自适应实现方案的UI流畅度分析

    本篇博客的主题是关于UI操作流畅度优化的一篇博客,我们以TableView中填充多个根据内容自适应高度的Cell来作为本篇博客的使用场景.当然Cell高度的自适应网上的解决方案是铺天盖地呢,今天我们的 ...

  7. UITableView自定义Cell中,纯代码编程动态获取高度

    在UITableView获取高度的代理方法中,经常需要根据实际的模型重新计算每个Cell的高度.直接的做法是在该代理方法中,直接根据模型来返回行高:另 [1]-(CGFloat)tableView:( ...

  8. 几种设置UITableView的cell动态高度的方法

    1.UITableView加载的顺序是先得到表的行的高度,也就是先调用heightForRowAtIndexPath方法,然后再调用cellForRowAtIndexPath,所以我们有两个办法实现自 ...

  9. UITableView cell 半透明效果,改变cell高度时背景不闪的解决方法

    如果直接指定cell.backgroundColor = = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 ...

随机推荐

  1. Unix 用gdb分析core dump文件

    产生core文件条件 用ulimit -c 指定core文件大小来开启core文件的生成,如:ulimit -c unlimited 用gdb分析core文件的条件 可执行程序在编译时,需加入-g参数 ...

  2. IOS 中openGL使用教程2(openGL ES 入门篇 | 绘制一个多边形)

    在上一篇我们学习了如何搭建IOS下openGL的开发环境,接下来我们来学习如何绘制一个多边形. 在2.0之前,es的渲染采用的是固定管线,何为固定管线,就是一套固定的模板流程,局部坐标变换 -> ...

  3. 十二、shapes

    1. The control points are attributes on the shape which are usually arrays of points. Control points ...

  4. c++学习--面向对象一实验

    实验内容 一 建立类cylinder,cylinder的构造函数被传递了两个double值,分别表示圆柱体的半径和高度.用类cylinder计算圆柱体的体积,并存储在一个double变量中.在类cyl ...

  5. DVD管理器集合版

    利用所学的集合写出的DVD管理系统,运用到了所学到集合基础. import java.text.ParseException; import java.text.SimpleDateFormat; i ...

  6. java知识点

    一.面向对象的五大基本原则: 1.单一职责原则(Single-Resposibility Principle):一个类,最好只做一件事,只有一个引起它的变化.单一职责原则可以看做是低耦合.高内聚在面向 ...

  7. onethink上传图片(资源)和预览

    直接上干货 不废话了 普通上传:  onthink框架 后台已经有图片和文件上传功能 controller里只需: public function addPicture(){ /* 调用文件上传组件上 ...

  8. Oracle:分割字符串 取TOP N条记录

    oracle数据库,表数据如下: ids                           id 3,4,5                        7 13,14,15,16         ...

  9. 用SQL语句获得一个存储过程返回的表

    1. 定义一个表变量 declare @table table(ReportType nvarchar(30),ReportPath nvarchar(200),ParaCnt int,DataAre ...

  10. Tomcat日志切割

    下载并解压缩 cronolog # tar zxvf cronolog-1.6.2.tar.gz 2.进入cronolog安装文件所在目录 # cd cronolog-1.6.2 3.运行安装  # ...