iOS UItableview 鑲嵌 collectionView ,cell 自適應高度動態布局


最近在寫這個功能,之前看到很多,可是需求一直沒有涉及到,大致思路是有的,發現,網上的大部分都有缺陷和bug,我也是好無語啦啦啦,也不曉得是不是升級 了xcode,一樣的代碼,允許的效果都不一樣,,,苦滋滋的,今天又寫了一遍,如果有問題請大家指出來。貼上代碼

 

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    self.contentView.backgroundColor=[UIColor redColor];
    [self.contentView addSubview:self.collection];
 // [self.contentView setNeedsLayout]; // [self.contentView layoutIfNeeded];
    [self.collection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(self.contentView);
        make.height.equalTo(@(Scale(130))).priorityLow();
       }];
}

- (void)setDataArry:(NSArray *)dataArry{
    _dataArry = dataArry;
    [self.collection reloadData];
    [self.collection mas_updateConstraints:^(MASConstraintMaker *make) {
  make.height.equalTo(@(self.collection.collectionViewLayout.collectionViewContentSize.height)).priorityLow();
        
    }];
}

這是圖片:

 

 

主要代碼如下:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM