https://lvwenhan.com/ios/449.html

#import "ViewController.h"
#import "MyTableViewCell.h"
static NSString *cellIdentifier = @"mycell"; @interface ViewController () <UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) NSArray *listArr;
@property (strong, nonatomic) MyTableViewCell *cell;
@end @implementation ViewController
@synthesize listArr; - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.tableView registerNib:[UINib nibWithNibName:@"MyTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:cellIdentifier];
self.tableView.estimatedRowHeight = ;//很重要保障滑动流畅性
self.cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier]; self.listArr = @[@"Do any additional setup after loading the view, typically from a nib.",
@"test",
@"UITableViewCell 高度自适应一直是我们做动态Cell高度时遇到的最烦躁的问题,Cell动态高度计算可以去看看 sunny 的这篇文章介绍,今天主要和大家分享下我在使用 systemLayoutSizeFittingSize 系统自带方法计算高度的一些心得!"];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return listArr.count;
} - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
MyTableViewCell *cell = self.cell;
cell.myLabel.text = listArr[indexPath.row];
cell.contentView.translatesAutoresizingMaskIntoConstraints = NO;
CGFloat fittingHeight = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return fittingHeight;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
self.cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (self.cell == nil) {
UINib *nib = [UINib nibWithNibName:@"MyTableViewCell" bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
self.cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
self.cell.myLabel.backgroundColor = [UIColor blueColor];
self.cell.myLabel.textColor = [UIColor whiteColor];
self.cell.myLabel.text = [listArr objectAtIndex:indexPath.row];
return self.cell;
} @end

autolayout 高度自适应的更多相关文章

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

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

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

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

  3. uitableviewcell高度自适应笔记

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

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

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

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

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

  6. SnapKit swift实现高度自适应的新浪微博布局

    SnapKit swift版的自动布局框架,第一次使用感觉还不错. SnapKit是一个优秀的第三方自适应布局库,它可以让iOS.OS X应用更简单地实现自动布局(Auto Layout).GtiHu ...

  7. iframe高度自适应(同域)

    今天解决了iframe高度自适应的问题,不过这只是同域下的页面嵌入,以下是代码: function SetCwinHeight(){ var iframeid = document.getElemen ...

  8. div仿textarea使高度自适应

    今天真的有些无语,在百度上找了很多关于textarea和input高度自适应的代码,并且考虑到了要判断textarea的滚动条,从而动态改变它的高度,直到我搜索了这个让我目瞪狗呆的办法…… <d ...

  9. 【代码笔记】iOS-UILable高度自适应(sizeWithFont)

    一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ...

随机推荐

  1. ASP.net的总结(一:理论理解)

    概述 这篇博客和之前博客有些重复的部分,如果要详细了解相应部分内容,可以到相应连接博客中查看.本篇博客主要介绍了什么是ASP.net,ASP.net在浏览器和服务器端的交互过程,ASP.net服务器端 ...

  2. 奇怪吸引子---LiuChen

    奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...

  3. Js实现页面关键字高亮显示

    <!DOCTYPE HTML> <html lang="en"> <meta http-equiv="Content-Type" ...

  4. phpstorm10使用服务激活

    现在官网已经更新到WebStorm 11.PhpStorm 10,找到一个很便捷的方法,不需要注册码了.安装完成,打开软件看到输入注册码界面的时候,切换到第二个选项,输入:http://idea.la ...

  5. Java:大文件拆分工具

    java大文件拆分工具(过滤掉表头) import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File ...

  6. .Net学习资料

    1.博客系列文章 (1)设计模式 吕震宇 设计模式 张逸:晴窗笔记 Design & Pattern 梦幻Dot Net  .Net设计模式 李会军          .NET设计模式系列文章 ...

  7. Adobe Photoshop CC2019中文破解版

    今天突发兴致玩PS, 之前安装的是CS6, 下载安装色相环插件后 先采用拷贝文件夹的方式将Coolorus放到plug-in下, 重启发现窗口>扩展程序 这项是灰色的. 于是采用安装coolor ...

  8. ubuntu下解压文件命令大全(转)

    ubuntu 下rar解压工具安装方法: 压缩功能 安装 sudo apt-get install rar卸载 sudo apt-get remove rar 解压功能 安装 sudo apt-get ...

  9. Adobe Photoshop for Mac(图像处理软件)破解版安装

    1.软件简介    Adobe Photoshop(简称 "PS")是 macOS 系统上一款由 Adobe Systems 开发和发行的图像处理软件.Photoshop 主要处理 ...

  10. arcgismanager登陆信息不对

    arcgis版本:arcgis10 安装arcgis server后(java版的win764位系统),发现arcgis管理器登陆界面(http://localhost:8099/arcgismana ...