// // FSBaseTopTableViewCell.m // FSScrollViewNestTableViewDemo // // Created by huim on 2017/5/23. // Copyright © 2017年 fengshun. All rights reserved. // #import "FSBaseTopTableViewCell.h" #import "FSLoopScrollView.h" #import "LDMorePicCollectionCell.h" #import "LDMorePicCollectionViewCell.h" #import "LDMorePicCollectionModel.h" @interface FSBaseTopTableViewCell () @property (nonatomic, strong) NSMutableArray *dataArr; @end static NSInteger sumCell=0; @implementation FSBaseTopTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { _imgv =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"super_back"]]; _imgv.frame=CGRectMake(0,KStatusBarHeight, SCREEN_WIDTH, Fitsize(115)); [self addSubview:_imgv]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; } - (void)setModelDatas:(NSArray *)dataArr { self.dataArr = [NSMutableArray arrayWithArray:dataArr]; if (self.dataArr.count !=0) { sumCell=self.dataArr.count; _collectionView=nil; for (UIView *view in self.subviews) { if ([view isKindOfClass:[UICollectionView class]]) { [view removeFromSuperview]; } } [self addSubview:self.collectionView]; [self.collectionView reloadData]; } } #pragma mark -UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ if (self.dataArr==nil||self.dataArr.count==0) { return 0; } return self.dataArr.count; } - ( UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ LDMorePicCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"picCollectionViewCell" forIndexPath:indexPath]; cell.backgroundColor =[UIColor YHColorWithHex:0xFFF3DE]; if (!cell) { } // LDMorePicCollectionModel *model=self.dataArr[indexPath.row]; // cell.titleLabel.text=model.name; // // [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@""]]; // [cell.picImageView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil]; return cell; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{ return 0; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{ return 0; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (self.delegate && [self.delegate respondsToSelector:@selector(YHMorePicCollectionCellDidSelectedItem:)]) { [self.delegate YHMorePicCollectionCellDidSelectedItem:indexPath.row]; } } - (UICollectionView *)collectionView { if (!_collectionView) { UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; if (sumCell==0) { sumCell=4; } NSInteger offHeight2=0; if (iPhone5) { offHeight2=10; } NSInteger Crow=1; NSInteger Coff=-1; NSInteger CrowItemSum=5; Coff=sumCell%CrowItemSum; if (Coff!=0) { CrowItemSum=4; Coff=sumCell%CrowItemSum; if (Coff!=0) { Coff=sumCell%3; CrowItemSum=3; if (Coff!=0) { CrowItemSum=5; } } } Crow=sumCell/CrowItemSum; if (Coff!=0) { Crow++; } float width=(SCREEN_WIDTH)/1.0f; flowLayout.itemSize = CGSizeMake((width-4)/CrowItemSum, SCREEN_WIDTH/4+offHeight2); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, KStatusBarHeight+Fitsize(115), width, (SCREEN_WIDTH/4+offHeight2)*Crow) collectionViewLayout:flowLayout]; _collectionView.layer.masksToBounds=YES; _collectionView.backgroundColor=[UIColor YHColorWithHex:0xFFF3DE]; _collectionView.delegate = self; _collectionView.dataSource = self; [_collectionView registerNib:[UINib nibWithNibName:@"LDMorePicCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"picCollectionViewCell"]; } return _collectionView; } @end