// // TFBookStoreNovelStyleThreeCell.m // TFReader // // Created by 谢腾飞 on 2020/12/16. // Copyright © 2020 xtfei_2011@126.com. All rights reserved. // #import "TFBookStoreNovelStyleThreeCell.h" #import "TFBookStoreNovelVerticalCell.h" #import "TFBookStoreNovelHorizontalCell.h" @implementation TFBookStoreNovelStyleThreeCell static NSString *verticalCell = @"TFBookStoreNovelVerticalCell"; static NSString *horizontalCell = @"TFBookStoreNovelHorizontalCell"; - (void)createSubviews { [super createSubviews]; self.collectionView.delegate = self; self.collectionView.dataSource = self; [self.collectionView registerClass:[TFBookStoreNovelVerticalCell class] forCellWithReuseIdentifier:verticalCell]; [self.collectionView registerClass:[TFBookStoreNovelHorizontalCell class] forCellWithReuseIdentifier:horizontalCell]; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { if (self.labelModel.list.count <= 3) { return 1; } return 2; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { if (self.labelModel.list.count <= 3) { return self.labelModel.list.count; } if (section == 0) { return 3; } return self.labelModel.list.count - 3; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { TFBookStoreNovelVerticalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:verticalCell forIndexPath:indexPath]; cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row]; return cell; } else { TFBookStoreNovelHorizontalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:horizontalCell forIndexPath:indexPath]; cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row + 3]; cell.hiddenEndLine = indexPath.row == self.labelModel.list.count - 3 - 1; return cell; } } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { return CGSizeMake(BOOK_WIDTH, VerticalCellHeight); } return CGSizeMake(SCREEN_WIDTH - kMargin, HorizontalCellHeight); } - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { if (section == 0) { return UIEdgeInsetsMake(0, kHalfMargin, 0, kHalfMargin); } return UIEdgeInsetsMake(kHalfMargin, kHalfMargin, 0, kHalfMargin); } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return kHalfMargin; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { TFProductionModel *labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.section * 3 + indexPath.row]; if (self.cellDidSelectItemBlock) { self.cellDidSelectItemBlock(labelListModel.production_id); } } @end