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

  1. #import "ViewController.h"
  2. #import "MyTableViewCell.h"
  3. static NSString *cellIdentifier = @"mycell";
  4.  
  5. @interface ViewController () <UITableViewDelegate, UITableViewDataSource>
  6. @property (strong, nonatomic) NSArray *listArr;
  7. @property (strong, nonatomic) MyTableViewCell *cell;
  8. @end
  9.  
  10. @implementation ViewController
  11. @synthesize listArr;
  12.  
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view, typically from a nib.
  16. [self.tableView registerNib:[UINib nibWithNibName:@"MyTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:cellIdentifier];
  17. self.tableView.estimatedRowHeight = ;//很重要保障滑动流畅性
  18. self.cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  19.  
  20. self.listArr = @[@"Do any additional setup after loading the view, typically from a nib.",
  21. @"test",
  22. @"UITableViewCell 高度自适应一直是我们做动态Cell高度时遇到的最烦躁的问题,Cell动态高度计算可以去看看 sunny 的这篇文章介绍,今天主要和大家分享下我在使用 systemLayoutSizeFittingSize 系统自带方法计算高度的一些心得!"];
  23. }
  24.  
  25. - (void)didReceiveMemoryWarning {
  26. [super didReceiveMemoryWarning];
  27. // Dispose of any resources that can be recreated.
  28. }
  29.  
  30. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  31. return ;
  32. }
  33.  
  34. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  35. return listArr.count;
  36. }
  37.  
  38. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
  39. MyTableViewCell *cell = self.cell;
  40. cell.myLabel.text = listArr[indexPath.row];
  41. cell.contentView.translatesAutoresizingMaskIntoConstraints = NO;
  42. CGFloat fittingHeight = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  43. return fittingHeight;
  44. }
  45.  
  46. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  47. self.cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  48.  
  49. if (self.cell == nil) {
  50. UINib *nib = [UINib nibWithNibName:@"MyTableViewCell" bundle:nil];
  51. [tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
  52. self.cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  53. }
  54. self.cell.myLabel.backgroundColor = [UIColor blueColor];
  55. self.cell.myLabel.textColor = [UIColor whiteColor];
  56. self.cell.myLabel.text = [listArr objectAtIndex:indexPath.row];
  57. return self.cell;
  58. }
  59.  
  60. @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. Knockout.Js官网学习(Mapping高级用法二)

    使用ignore忽略不需要map的属性 如果在map的时候,你想忽略一些属性,你可以使用ignore累声明需要忽略的属性名称集合: " }; var mapping = { 'ignore' ...

  2. Android关于log日志,华为不输出log.v,log.d(zz)

    [java] view plain copy 我用的是mate8,本来虚拟机测试一点日志一点问题没有 [java] view plain copy 但是真机测试发现log.d一直不输出,正好又试了lo ...

  3. yum离线安装rpm包

    CentOS利用yum下载好rpm包,并离线安装   1.联网安装好rpm包,并将下载好的包备好 #yum install --downloadonly --downloaddir=/home/sam ...

  4. java 通用取得 系统硬件信息及 jvm 信息的 jar 包 oshi-core

    maven 引用 <dependency> <groupId>com.github.dblock</groupId> <artifactId>oshi- ...

  5. FTP上传、下载(简单小例子)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  6. IOS开发系列之阿堂教程:玩转IPhone客户端和Web服务端交互(客户端)实践

    说到ios的应用开发,我们不能不提到web server服务端,如果没有服务端的支持,ios应用开发就没有多大意义了,因为从事过手机开发的朋友都知道(Android也一样),大量复杂业务的处理和数据库 ...

  7. 《转》vue更新到2.0之后vue-resource不在更新,axios的使用

    vue更新到2.0之后,作者就宣告不再对vue-resource更新,而是推荐的axios,前一段时间用了一下,现在说一下它的基本用法. 首先就是引入axios,如果你使用es6,只需要安装axios ...

  8. 《软件测试自动化之道》读书笔记 之 SQL 存储过程测试

    <软件测试自动化之道>读书笔记 之 SQL 存储过程测试 2014-09-28 待测程序测试程序   创建测试用例以及测试结果存储  执行T-SQL脚本  使用BCP工具导入测试用例数据  ...

  9. 9款最好的JavaScript压缩工具

    削减是一个从源代码中删除不必要的字符的技术使它看起来简单而整洁.这种技术也被称为代码压缩和最小化.在这里,我们为你收集了10个最好的JavaScript压缩工具将帮助您删除不必要的空格,换行符,评论, ...

  10. idea 导入 android项目

    1. 2. 主要是勾选上面选项. next next 导入即可