cranz-jf

单元格的高度自适应原理就是通过内部label的高度变化来增加和减少单元格的高度。

- (UILabel *)label {

if(_label == nil) {

_label = [[UILabel alloc] init];

        [self.contentView addSubview:_label];

        _label.numberOfLines = 0;

        [_label mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.top.mas_equalTo(10);

            make.right.mas_equalTo(-10);

            make.height.mas_lessThanOrEqualTo(1000);// 设置的足够大就好

            make.bottom.mas_lessThanOrEqualTo(-10);

        }];

}

return _label;

}

 

*************

*************

在设置tableView的时候,要设置最主要的两句:

self.tableView.rowHeight = UITableViewAutomaticDimension;//自适应规格  

self.tableView.estimatedRowHeight = 1000;//这个值随便设置。别是0或者1就行!

OK。这个时候,单元格已经可以实现高度自适应了。

 

分类:

技术点:

相关文章:

  • 2021-04-02
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2021-12-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2021-12-21
  • 2021-12-22
  • 2021-12-26
  • 2021-12-21
相关资源
相似解决方案