123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- //
- // 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 ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
- @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
|