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
3.0 KiB

//
// TFMemberPrivilegeViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/13.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFMemberPrivilegeViewCell.h"
#import "TFMemberPrivilegeItemCell.h"
@interface TFMemberPrivilegeViewCell ()
{
UICollectionView *mainCollectionView;
}
@end
@implementation TFMemberPrivilegeViewCell
- (void)createSubviews
{
[super createSubviews];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumLineSpacing = 0;
flowLayout.minimumInteritemSpacing = 0;
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH / 4 , SCREEN_WIDTH / 4);
mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
[mainCollectionView registerClass:[TFMemberPrivilegeItemCell class] forCellWithReuseIdentifier:@"TFMemberPrivilegeItemCell"];
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).with.offset(kHalfMargin);
make.width.mas_equalTo(self.contentView.mas_width);
make.height.mas_equalTo(SCREEN_WIDTH / 4);
make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow();
}];
}
- (void)setPrivilege:(NSArray<TFPrivilegeModel *> *)privilege
{
_privilege = privilege;
if (privilege.count > 0) {
[mainCollectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo((SCREEN_WIDTH / 4) * (privilege.count % 4 == 0?(privilege.count / 4):((privilege.count / 4) + 1)));
}];
[mainCollectionView reloadData];
}
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.privilege.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TFMemberPrivilegeItemCell";
TFMemberPrivilegeItemCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.privilegeModel = [self.privilege objectOrNilAtIndex:indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
// TFProductionModel *labelListModel = [self.model.list objectOrNilAtIndex:indexPath.row];
// if (self.cellDidSelectItemBlock) {
// self.cellDidSelectItemBlock(labelListModel.production_id);
// }
}
@end