You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.7 KiB

//
// TFBookStoreNovelStyleFourCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFBookStoreNovelVerticalCell.h"
#import "TFBookStoreNovelHorizontalCell.h"
@implementation TFBookStoreNovelStyleFourCell
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 <= 1) {
return 1;
}
return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (self.labelModel.list.count <= 1) {
return 1;
}
if (section == 0) {
return 1;
} else {
return self.labelModel.list.count > 3?3:self.labelModel.list.count - 1;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
TFBookStoreNovelHorizontalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:horizontalCell forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = YES;
return cell;
} else {
TFBookStoreNovelVerticalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:verticalCell forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row + 1];
return cell;
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return CGSizeMake(SCREEN_WIDTH - kMargin, HorizontalCellHeight);
}
return CGSizeMake(BOOK_WIDTH, VerticalCellHeight);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.section + indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(labelListModel.production_id);
}
}
@end