OC TableView 根據(jù)內(nèi)容獲取高度 2

根據(jù)約束適配cell高度。不用實現(xiàn)- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 方法

cell.m

- (void)masMake {

    [self.detailLab  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(leftPadding * 2);
        make.height.mas_equalTo(20);
    }];

    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.detailLab.mas_bottom).offset(leftPadding * 2);
        make.left.equalTo(self.contentView).offset(leftPadding/2.0);
        make.right.equalTo(self.contentView).offset(-leftPadding/2.0);
        make.bottom.equalTo(self.contentView);
        make.height.mas_greaterThanOrEqualTo(20);
    }];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(leftPadding);
        make.right.equalTo(self.contentView).offset(-leftPadding);
        make.top.equalTo (self.bgView).offset(leftPadding);
        make.bottom.equalTo(self.imgView.mas_top);
        make.height.mas_greaterThanOrEqualTo(20);
    }];
    //圖片
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab);
        make.right.equalTo(self.titleLab);
        make.bottom.equalTo(self.bgView).offset(- leftPadding);
        make.height.mas_greaterThanOrEqualTo(0);
    }];

}

tableView里設置

   _tableView.rowHeight = UITableViewAutomaticDimension;
   _tableView.estimatedRowHeight = 100;
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 一、簡介 <<UITableView(或簡單地說,表視圖)的一個實例是用于顯示和編輯分層列出的信息的一種手段 <<...
    無邪8閱讀 10,962評論 3 3
  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴謹 對...
    cosWriter閱讀 11,666評論 1 32
  • 我們在上一篇《通過代碼自定義不等高cell》中學習了tableView的相關知識,本文將在上文的基礎上,利用sto...
    啊世ka閱讀 1,655評論 2 7
  • 概述在iOS開發(fā)中UITableView可以說是使用最廣泛的控件,我們平時使用的軟件中到處都可以看到它的影子,類似...
    liudhkk閱讀 9,299評論 3 38
  • 1.ios高性能編程 (1).內(nèi)層 最小的內(nèi)層平均值和峰值(2).耗電量 高效的算法和數(shù)據(jù)結(jié)構(gòu)(3).初始化時...
    歐辰_OSR閱讀 30,246評論 8 265

友情鏈接更多精彩內(nèi)容