1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- //
- // DRClassifyRightView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/4/28.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRClassifyRightView.h"
- #import "DRClassifyRightCollectionViewCell.h"
- #import "DRCategoryModel.h"
- #import "DRSecondCategoryModel.h"
- static NSString *const itemIdentifier = @"itemIdentifier";
- @interface DRClassifyRightView()<UICollectionViewDelegate,UICollectionViewDataSource>
- @property (nonatomic,strong)UICollectionView *collectionView;
- @end
- @implementation DRClassifyRightView
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self == [super initWithFrame:frame]) {
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI{
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
- flowLayout.itemSize = CGSizeMake(self.width / 3, FITSIZE(114));
- flowLayout.minimumLineSpacing = 0;
- flowLayout.minimumInteritemSpacing = 0;
- self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height) collectionViewLayout:flowLayout];
- self.collectionView.backgroundColor = [UIColor whiteColor];
- [self.collectionView registerClass:[DRClassifyRightCollectionViewCell class] forCellWithReuseIdentifier:itemIdentifier];
- self.collectionView.showsVerticalScrollIndicator = NO;
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- [self addSubview:self.collectionView];
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return self.dataSource.count;
- }
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- DRClassifyRightCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:itemIdentifier forIndexPath:indexPath];
- DRSecondCategoryModel *model = self.dataSource[indexPath.item];
- cell.model = model;
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- [self.collectionView deselectItemAtIndexPath:indexPath animated:YES];
- if (self.selectItemBlock) {
- self.selectItemBlock(indexPath.item);
- }
- }
- - (void)setDataSource:(NSArray *)dataSource{
- _dataSource = dataSource;
- [self.collectionView reloadData];
- }
- @end
|