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.
 

85 lines
2.9 KiB

//
// TFUpgradeMemberViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/13.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFUpgradeMemberViewCell.h"
#import "TFUpgradeMemberItemCell.h"
#import "WXYZ_ShadowView.h"
@interface TFUpgradeMemberViewCell ()
{
UICollectionView *mainCollectionView;
NSInteger selectIndex;
}
@end
@implementation TFUpgradeMemberViewCell
- (void)createSubviews
{
[super createSubviews];
selectIndex = 0;
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumLineSpacing = kMargin;
flowLayout.minimumInteritemSpacing = 0;
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH - 5 * kMargin) / 3 , (SCREEN_WIDTH - 5 * kMargin) / 3 * 1.1);
flowLayout.sectionInset = UIEdgeInsetsMake(0, kHalfMargin, 0, kHalfMargin);
mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
[mainCollectionView registerClass:[TFUpgradeMemberItemCell class] forCellWithReuseIdentifier:@"TFUpgradeMemberItemCell"];
mainCollectionView.backgroundColor = [UIColor clearColor];
mainCollectionView.alwaysBounceVertical = NO;
mainCollectionView.showsVerticalScrollIndicator = NO;
mainCollectionView.showsHorizontalScrollIndicator = NO;
mainCollectionView.delegate = self;
mainCollectionView.dataSource = self;
[self.contentView addSubview:mainCollectionView];
[mainCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left);
make.top.mas_equalTo(self.contentView.mas_top);
make.width.mas_equalTo(self.contentView.mas_width);
make.height.mas_equalTo((SCREEN_WIDTH - 5 * kMargin) / 3 * 1.1 + kMargin);
make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow();
}];
}
- (void)setGoodsList:(NSArray<TFGoodsModel *> *)goodsList
{
_goodsList = goodsList;
[mainCollectionView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.goodsList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TFUpgradeMemberItemCell";
TFUpgradeMemberItemCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.goodsModel = [self.goodsList objectOrNilAtIndex:indexPath.row];
cell.cellSelected = selectIndex == indexPath.row;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
selectIndex = indexPath.row;
[mainCollectionView reloadData];
if (self.selectItemBlock) {
self.selectItemBlock(indexPath.row);
}
}
@end