// // YOUPAIZYUserZiLiaoDTCell.m // VQU // // Created by 肖浩然的mac on 2021/7/10. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAIZYUserZiLiaoDTCell.h" #import "YOUPAIZYUserZiLiaoDTPhotoCell.h" #import "YOUPAILCDynamicArrayModel.h" @interface YOUPAIZYUserZiLiaoDTCell() @property (nonatomic, strong) UICollectionView *youpaipcollectionView; @end @implementation YOUPAIZYUserZiLiaoDTCell -(instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self youpaifsetSubView]; } return self; } -(void)youpaifsetSubView{ UIView *titleView = [UIView new]; [self.contentView addSubview:titleView]; [titleView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.height.mas_equalTo(17); }]; titleView.backgroundColor = [UIColor whiteColor]; self.youpaiptitleLabel = [[UILabel alloc] init]; [titleView addSubview:self.youpaiptitleLabel]; [self.youpaiptitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(0); make.left.mas_equalTo(14); }]; self.youpaiptitleLabel.textColor = [UIColor whiteColor]; //arrow UIButton *arrowBtn = [UIButton new]; [self.contentView addSubview:arrowBtn]; [arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(70); make.centerY.mas_equalTo(self.youpaiptitleLabel); make.right.mas_equalTo(-6); }]; [arrowBtn setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft]; [arrowBtn setImage:[UIImage imageNamed:@"vqu_images_zhuye_ZL_arrow"] forState:UIControlStateNormal]; [arrowBtn addTarget:self action:@selector(youpaifarrowBtnClick) forControlEvents:UIControlEventTouchUpInside]; [arrowBtn setTitle:@"查看全部" forState:UIControlStateNormal]; arrowBtn.titleLabel.font = [UIFont systemFontOfSize:10]; [arrowBtn setTitleColor:HexColorFromRGB(0xA3AABE) forState:UIControlStateNormal]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; self.youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; [self.contentView addSubview:self.youpaipcollectionView]; [self.youpaipcollectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(titleView.mas_bottom).offset(9); make.left.mas_offset(12.f); make.right.mas_offset(0); make.bottom.mas_offset(0.f); }]; self.youpaipcollectionView.userInteractionEnabled = NO; self.youpaipcollectionView.backgroundColor = [UIColor whiteColor]; self.youpaipcollectionView.showsVerticalScrollIndicator = NO; self.youpaipcollectionView.showsHorizontalScrollIndicator = NO; self.youpaipcollectionView.bounces = NO; [self.youpaipcollectionView registerClass:[YOUPAIZYUserZiLiaoDTPhotoCell class] forCellWithReuseIdentifier:NSStringFromClass([YOUPAIZYUserZiLiaoDTPhotoCell class])]; self.youpaipcollectionView.delegate = self; self.youpaipcollectionView.dataSource = self; } -(void)setYoupaipalbumArray:(NSArray *)albumArray{ _youpaipalbumArray = albumArray; if (albumArray.count>0) { NSInteger count = 0; if (albumArray.count>=5) { count = 5; }else{ count =albumArray.count; } NSMutableArray *arr = [NSMutableArray new]; for (int i = 0; i /** 返回区数 @param collectionView 集合视图 @return 返回区数 */ - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } /** 返回项目数 @param collectionView 集合视图 @param section 区 @return 项目数 */ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.youpaipalbumArray.count; } -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ // NSString *imageUrl = self.albumArray[indexPath.item]; YOUPAIZYUserZiLiaoDTPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YOUPAIZYUserZiLiaoDTPhotoCell class]) forIndexPath:indexPath]; YOUPAILCDynamicArrayModel *model = self.youpaipalbumArray[indexPath.item]; if (model.youpaiptype == 1) {//视频 cell.youpaipplayImageView.hidden = NO; [cell.youpaipiconImageView sd_setImageWithURL:[NSURL URLWithString:model.youpaipurl] placeholderImage:nil]; }else{ cell.youpaipplayImageView.hidden = YES; [cell.youpaipiconImageView sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipurl] placeholderImage:nil]; } return cell; } -(void)youpaifarrowBtnClick{ if ([self.youpaipdelegate respondsToSelector:@selector(youpaifDTDidCellOrBtnclick)]) { [self.youpaipdelegate youpaifDTDidCellOrBtnclick]; } } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if ([self.youpaipdelegate respondsToSelector:@selector(youpaifDTDidCellOrBtnclick)]) { [self.youpaipdelegate youpaifDTDidCellOrBtnclick]; } } #pragma mark UICollectionViewDelegateFlowLayout /** 项目大小 @param collectionView 集合视图 @param collectionViewLayout 布局 @param indexPath 布局 @return 大小 */ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(63, 63); } #pragma mark - X间距 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 2.0; } //设置段落的内边距 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0,0,0,0);//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) } @end