// // ASCategaryListCell.m // Asteria // // Created by iOS on 2023/6/6. // #import "ASCategaryListCell.h" #import "ASCategaryCollectCell.h" #import "ASJumpModel.h" @interface ASCategaryListCell () @property (nonatomic, strong) UICollectionView *collV; @end @implementation ASCategaryListCell - (void)setArr:(NSArray *)arr { _arr = arr; [self.collV reloadData]; } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.contentView.backgroundColor = UIColor.whiteColor; [self.contentView addSubview:self.collV]; [self.collV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(30); make.leading.trailing.equalTo(self.contentView); make.height.equalTo(@112); make.bottom.equalTo(self.contentView).offset(-25); }]; } return self; } - (UICollectionView *)collV { if (!_collV) { UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new]; layout.itemSize = CGSizeMake(112, 112); layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10); layout.minimumLineSpacing = 5; layout.minimumInteritemSpacing = 5; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; UICollectionView *col = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 112) collectionViewLayout:layout]; [col registerClass:[ASCategaryCollectCell class] forCellWithReuseIdentifier:@"ASCategaryCollectCell"]; col.showsHorizontalScrollIndicator = false; col.delegate = self; col.dataSource = self; col.backgroundColor = UIColor.whiteColor; _collV = col; } return _collV; } // MARK: - coll delegate datasource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return _arr.count; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { ASCategaryCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ASCategaryCollectCell" forIndexPath:indexPath]; if (self.arr.count <= indexPath.row) { return cell; } ASJumpModel *m = self.arr[indexPath.row]; [cell.imgV sd_setImageWithURL:[NSURL URLWithString:m.image]]; cell.titleLb.text = m.title; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (self.arr.count <= indexPath.row) { return ; } ASJumpModel *m = self.arr[indexPath.row]; if (self.selectCategory) { self.selectCategory(m, indexPath); } } @end