| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // MOGradeCollectionCell.m
- // MiMoLive
- //
- // Created by SuperC on 2023/12/27.
- //
- #import "MOGradeCollectionCell.h"
- @interface MOGradeCollectionCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
- @property (nonatomic, strong) UICollectionView *collectionView;
- @end
- @implementation MOGradeCollectionCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self != nil) {
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
-
- [self setupUI];
- }
-
- return self;
- }
- - (void)setupUI{
- [self.contentView addSubview:self.collectionView];
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentView);
- }];
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (void)setDataArr:(NSArray *)dataArr{
- _dataArr = dataArr;
- [self.collectionView reloadData];
- }
- #pragma mark --UICollectionViewDatasource & delegate
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return self.dataArr.count;
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- MOPrivilegesItemInfo *model = self.dataArr[indexPath.row];
- MOGradeInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOGradeInfoCell_ID forIndexPath:indexPath];
- cell.level = self.level;
- cell.cellModel = model;
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
-
- MOPrivilegesItemInfo *model = self.dataArr[indexPath.row];
- self.cellClickBlock ? self.cellClickBlock(model) : nil;
- }
- - (UICollectionView *)collectionView{
- if (!_collectionView)
- {
- CGFloat collectionWidth = SCREENWIDTH - 4.0;
-
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
- layout.minimumLineSpacing = 5.0;
- layout.minimumInteritemSpacing = 0.0;
- layout.itemSize = CGSizeMake(collectionWidth / 4.0 ,120.0);
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, collectionWidth, collectionWidth / 2) collectionViewLayout:layout];
- [self.collectionView registerNib:[UINib nibWithNibName:@"MOGradeInfoCell" bundle:nil] forCellWithReuseIdentifier:MOGradeInfoCell_ID];
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- _collectionView.showsVerticalScrollIndicator = NO;
- _collectionView.backgroundColor = [UIColor clearColor];
- _collectionView.scrollEnabled = NO;
- }
- return _collectionView;
- }
- @end
|