《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRClassifyRightView.m 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // DRClassifyRightView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/4/28.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRClassifyRightView.h"
  9. #import "DRClassifyRightCollectionViewCell.h"
  10. #import "DRCategoryModel.h"
  11. #import "DRSecondCategoryModel.h"
  12. static NSString *const itemIdentifier = @"itemIdentifier";
  13. @interface DRClassifyRightView()<UICollectionViewDelegate,UICollectionViewDataSource>
  14. @property (nonatomic,strong)UICollectionView *collectionView;
  15. @end
  16. @implementation DRClassifyRightView
  17. - (instancetype)initWithFrame:(CGRect)frame{
  18. if (self == [super initWithFrame:frame]) {
  19. [self setupUI];
  20. }
  21. return self;
  22. }
  23. - (void)setupUI{
  24. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  25. flowLayout.itemSize = CGSizeMake(self.width / 3, FITSIZE(114));
  26. flowLayout.minimumLineSpacing = 0;
  27. flowLayout.minimumInteritemSpacing = 0;
  28. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height) collectionViewLayout:flowLayout];
  29. self.collectionView.backgroundColor = [UIColor whiteColor];
  30. [self.collectionView registerClass:[DRClassifyRightCollectionViewCell class] forCellWithReuseIdentifier:itemIdentifier];
  31. self.collectionView.showsVerticalScrollIndicator = NO;
  32. self.collectionView.delegate = self;
  33. self.collectionView.dataSource = self;
  34. [self addSubview:self.collectionView];
  35. }
  36. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  37. return self.dataSource.count;
  38. }
  39. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  40. DRClassifyRightCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:itemIdentifier forIndexPath:indexPath];
  41. DRSecondCategoryModel *model = self.dataSource[indexPath.item];
  42. cell.model = model;
  43. return cell;
  44. }
  45. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  46. [self.collectionView deselectItemAtIndexPath:indexPath animated:YES];
  47. if (self.selectItemBlock) {
  48. self.selectItemBlock(indexPath.item);
  49. }
  50. }
  51. - (void)setDataSource:(NSArray *)dataSource{
  52. _dataSource = dataSource;
  53. [self.collectionView reloadData];
  54. }
  55. @end