// // PBScheduleImgTableViewCell.m // IphoneBIMe // // Created by ZhangJF on 2022/9/9. // Copyright © 2022 ProBIM. All rights reserved. // #import "PBScheduleImgTableViewCell.h" #import "PBImgAndNameCollectionViewCell.h" #import "PBImageModel.h" static NSString *const cellID = @"cellID"; @interface PBScheduleImgTableViewCell() @property (nonatomic, weak) UICollectionView *collectionView; //图片 @end @implementation PBScheduleImgTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setupUI]; } return self; } - (void)setupUI { UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout.alloc init]; layout.itemSize = CGSizeMake(168, 140); layout.minimumLineSpacing = 10; layout.minimumInteritemSpacing = 0; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; UICollectionView *collectionView = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout]; [collectionView registerClass:[PBImgAndNameCollectionViewCell class] forCellWithReuseIdentifier:cellID]; collectionView.delegate = self; collectionView.dataSource = self; collectionView.pagingEnabled = YES; // _collectionView.bounces = NO; collectionView.showsHorizontalScrollIndicator = NO; collectionView.backgroundColor = [UIColor whiteColor]; // collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 100); [self.contentView addSubview:collectionView]; [collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView); make.left.equalTo(self.contentView).offset(12); make.right.equalTo(self.contentView).offset(-12); make.bottom.equalTo(self.contentView); make.height.mas_equalTo(@140); }]; self.collectionView = collectionView; } #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.imageArr.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { PBImgAndNameCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath]; PBImageModel *model = self.imageArr[indexPath.row]; cell.model = model; cell.DeleteImageBlock = ^{ if (model.bf_path) { if (self.DeleteImageBlock){ self.DeleteImageBlock(indexPath.item); } }else { [self.imageArr removeObjectAtIndex:indexPath.row]; [self.collectionView reloadData]; } }; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { SDPhotoBrowser *photoBrowser = [SDPhotoBrowser new]; photoBrowser.delegate = self; photoBrowser.currentImageIndex = indexPath.item; photoBrowser.imageCount = self.imageArr.count; // photoBrowser.sourceImagesContainerView = self.collectionView; [photoBrowser show]; } #pragma mark SDPhotoBrowserDelegate // 返回临时占位图片(即原来的小图) - (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index { // 不建议用此种方式获取小图,这里只是为了简单实现展示而已 PBImgAndNameCollectionViewCell *cell = (PBImgAndNameCollectionViewCell *)[self collectionView:self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]]; // if (self.isAddExamine) { return cell.imageV.image; // }else { // NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:cell.imageUrl]]; // UIImage *image = [UIImage imageWithData:data];; // return image; // } } - (void)setImageArr:(NSMutableArray *)imageArr { _imageArr = imageArr; [self.collectionView reloadData]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end