通过autoLayout自适应tableviewCell高度

2019-04-10  本文已影响0人  夏日冰霜
tableviewCell具体代码:
CGFloat maxWidth = [UIScreen mainScreen].bounds.size.width - 10 * 2;
    
    self.tempLabel = [UILabel getLabelWithFont:FMedium(20) textColor:C_Black_333333 superView:self.contentView masonrySet:^(UILabel *view, MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).with.offset(10);
        make.left.equalTo(self.contentView).with.offset(10);
        make.right.equalTo(self.contentView).with.offset(-10);
        make.bottom.equalTo(self.contentView).with.offset(-10);
        
        view.numberOfLines = 0;
        view.preferredMaxLayoutWidth = maxWidth;
    }];
    
    [self.tempLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];

tableviewDelegate返回高度的方法:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewAutomaticDimension;
}

支持版本为iOS 8以上的话才可以直接利用UITableViewAutomaticDimension在tableview的heightForRowAtIndexPath直接返回哦。如果需要iOS 8以下版本的自适应高度,私信给我。


希望给个小心心支持一下😘~

上一篇 下一篇

猜你喜欢

热点阅读