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. ionic 布局

    1. row col 设置自动换行 <!--长文本换行 item-text-wrap--> <li class="item item-text-wrap" ng- ...

  2. wine qq 2013 for linux deb包 Ubuntu 64位兼容

    2013-08-08     Wine 1.6,如果您想体验下该版本的wine,目前可以通过ppa进行安装:   sudo add-apt-repository ppa:ubuntu-wine/ppa ...

  3. Netty+MUI从零打造一个仿微信的高性能聊天项目,兼容iPhone/iPad/安卓

    要说到微信,我相信是个人都应该知道,几乎人人都会安装这款社交APP吧,它已经成为了我们生活中不可缺少的一份子. 我记得我上大学那会刚接触Java,做的第一个小项目就是基于J2SE的聊天室,使用Java ...

  4. python 列表排序方法sort、sorted技巧篇

    Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列. 1)排序基础 简单的升序排序是非常容易的.只需要调用sorte ...

  5. JAVA(五)反射机制/Annotation

    成鹏致远 | lcw.cnblog.com |2014-02-04 反射机制 1.认识Class类 在正常情况下,必须知道一个类的完整路径之后才可以实例化对象,但是在 java中也允许通过一个对象来找 ...

  6. 【转】css3实现文字闪烁,改变透明度

    <style> @-webkit-keyframes shake{ 0%{ opacity: 1; } 50%{ opacity: 0.5; } 100%{ opacity: 1; } } ...

  7. 【转】Ubuntu FireFox无法播放网页视频音乐的解决办法

    原文:http://www.codeweblog.com/%E8%A7%A3%E5%86%B3qq%E9%9F%B3%E4%B9%90%E7%BD%91%E9%A1%B5%E7%89%88%E5%9C ...

  8. Git的使用(一)

    最近在解除git的使用,开始觉得git某些地方还是挺方便的. 1.svn的话管理起来是比较方便,可是断网的话,会用不了 2.git的话,管理一些开源的东西比较方便,并且比较好管理日常写的demo程序, ...

  9. Centos 编译安装nodejs&express框架

    一. 下载nodejs 版本 wget http://nodejs.org/dist/v0.10.28/node-v0.10.28.tar.gz 二. 编译安装 cp node-v0.10.28.ta ...

  10. centos 6.4 使用epel 源

    EPEL是RHEL 的 Fedora 软件仓库,把它添上,你就可以获得 RHEL AS 的高质量.高性能.高可靠性,又需要方便易用(关键是免费)的软件包更新功能.EPEL(Extra Packages ...