酷店

KDPSupplyCommentViewCell.m 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // KDPSupplyCommentViewCell.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/4.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPSupplyCommentViewCell.h"
  9. #import "KDPClassModel.h"
  10. @interface KDPSupplyCommentViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
  11. @property (nonatomic, strong) UICollectionView *collectionView;
  12. @end
  13. @implementation KDPSupplyCommentViewCell
  14. - (instancetype)initWithFrame:(CGRect)frame{
  15. if (self = [super initWithFrame:frame]) {
  16. self.contentView.layer.cornerRadius = 8;
  17. self.contentView.layer.masksToBounds = YES;
  18. self.contentView.backgroundColor = [UIColor whiteColor];
  19. [self setUpSubViews];
  20. }
  21. return self;
  22. }
  23. - (void)setUpSubViews{
  24. [self.contentView addSubview:self.collectionView];
  25. }
  26. - (UICollectionView *)collectionView{
  27. if (!_collectionView) {
  28. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  29. flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH-20)/4, 90);
  30. flowLayout.minimumLineSpacing = 0;
  31. flowLayout.minimumInteritemSpacing = 0;
  32. _collectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:flowLayout];
  33. _collectionView.dataSource = self;
  34. _collectionView.delegate = self;
  35. _collectionView.showsHorizontalScrollIndicator = NO;
  36. _collectionView.showsVerticalScrollIndicator = NO;
  37. _collectionView.scrollEnabled = NO;
  38. _collectionView.backgroundColor = [UIColor whiteColor];
  39. [_collectionView registerClass:[KDPSupplyCommentContentCell class] forCellWithReuseIdentifier:NSStringFromClass([KDPSupplyCommentContentCell class])];
  40. }
  41. return _collectionView;
  42. }
  43. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  44. KDPSupplyCommentContentCell *contentCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KDPSupplyCommentContentCell class]) forIndexPath:indexPath];
  45. [contentCell configCellWithModel:self.dataArray[indexPath.row] indexPath:indexPath];
  46. return contentCell;
  47. }
  48. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  49. return 1;
  50. }
  51. - (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  52. return self.dataArray.count >= 8 ? 8 : self.dataArray.count;
  53. }
  54. - (void)setDataArray:(NSArray *)dataArray{
  55. _dataArray = dataArray;
  56. [self.collectionView reloadData];
  57. }
  58. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  59. if ([self.delegate respondsToSelector:@selector(commentCollectionView:didSelectIndex:)]) {
  60. [self.delegate commentCollectionView:collectionView didSelectIndex:indexPath.row];
  61. }
  62. }
  63. @end
  64. @implementation KDPSupplyCommentContentCell
  65. {
  66. UIImageView *_commentImageView;
  67. UILabel *_commentLabel;
  68. }
  69. - (instancetype)initWithFrame:(CGRect)frame{
  70. if (self = [super initWithFrame:frame]) {
  71. [self setUpSubViews];
  72. [self setSubViewsConstraints];
  73. }
  74. return self;
  75. }
  76. - (void)setUpSubViews{
  77. _commentImageView = [[UIImageView alloc] init];
  78. [self.contentView addSubview:_commentImageView];
  79. _commentLabel = [[UILabel alloc] init];
  80. _commentLabel.font = FONT_SYS(13);
  81. _commentLabel.textColor = [UIColor colorWithRGB:0x666666];
  82. _commentLabel.textAlignment = NSTextAlignmentCenter;
  83. [self.contentView addSubview:_commentLabel];
  84. }
  85. - (void)setSubViewsConstraints{
  86. [_commentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.top.equalTo(self.contentView.mas_top).offset(30);
  88. make.size.equalTo(CGSizeMake(20, 35));
  89. make.centerX.equalTo(self.contentView);
  90. }];
  91. [_commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.top.equalTo(self->_commentImageView.mas_bottom).offset(3);
  93. make.left.equalTo(self.contentView.mas_left).offset(10);
  94. make.right.equalTo(self.contentView.mas_right).offset(-10);
  95. make.centerX.equalTo(self.contentView);
  96. }];
  97. }
  98. - (void)configCellWithModel:(id)model indexPath:(NSIndexPath *)indexpath{
  99. KDPClassModel *goodModel = (KDPClassModel *)model;
  100. [_commentImageView sd_setImageWithURL:[NSURL URLWithString:goodModel.icon]placeholderImage:[UIImage imageNamed:placholderImg]];
  101. _commentLabel.text = goodModel.name;
  102. }
  103. @end