12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- //
- // KBModuleView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/7/4.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBModuleView.h"
- #import "KBModuleCollectionCell.h"
- static NSString *ldModuleCollectionCell = @"ldModuleCollectionCell";
- @interface KBModuleView()<UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>{
- NSArray *_dataArr;
- }
- @property (nonatomic, strong) UICollectionView *collectionView;
- @end
- @implementation KBModuleView
- - (void)setRecommonData:(NSArray *)dataArr {
- _dataArr = dataArr.mutableCopy;
- [self.collectionView reloadData];
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.layer.masksToBounds = YES;
- [self initSubView];
- }
- return self;
- }
- - (void)initSubView {
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
- self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height) collectionViewLayout:flowLayout];
- flowLayout.minimumLineSpacing = 5;
- flowLayout.minimumInteritemSpacing = 10;
- flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- self.collectionView.backgroundColor = [UIColor whiteColor];
- [self.collectionView registerClass:[KBModuleCollectionCell class] forCellWithReuseIdentifier:ldModuleCollectionCell];
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- self.collectionView.showsHorizontalScrollIndicator = NO;
- [self addSubview:self.collectionView];
- }
- #pragma mark ---- UICollectionView Delegate ------
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return CGSizeMake((SCREEN_WIDTH-30)/3, self.collectionView.height);
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return _dataArr.count;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
- {
- return CGSizeMake(0, 0);
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
- {
- return CGSizeMake(0, 0);
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- KBChildGoodModel *model = _dataArr[indexPath.row];
- KBModuleCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:ldModuleCollectionCell forIndexPath:indexPath];
- cell.model = model;
- return cell;
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
-
- return UIEdgeInsetsMake(0, 10, 0, 0);
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- KBChildGoodModel *model = _dataArr[indexPath.row];
- if (self.didSelectedGood) {
- self.didSelectedGood(model);
- }
- }
- @end
|