最近在寫這個功能,以前看到不少,但是需求一直沒有涉及到,大體思路是有的,發現,網上的大部分都有缺陷和bug,我也是好無語啦啦啦,也不曉得是否是升級 了xcode,同樣的代碼,容許的效果都不同,,,苦滋滋的,今天又寫了一遍,若是有問題請你們指出來。貼上代碼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(); }]; }
這是圖片:spa
主要代碼以下:code