123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- //
- // KDPSupplyCommentViewCell.m
- // KuDianProject
- //
- // Created by admin on 2019/7/4.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPSupplyCommentViewCell.h"
- #import "KDPClassModel.h"
- @interface KDPSupplyCommentViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
- @property (nonatomic, strong) UICollectionView *collectionView;
- @end
- @implementation KDPSupplyCommentViewCell
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- self.contentView.layer.cornerRadius = 8;
- self.contentView.layer.masksToBounds = YES;
- self.contentView.backgroundColor = [UIColor whiteColor];
- [self setUpSubViews];
- }
- return self;
- }
- - (void)setUpSubViews{
- [self.contentView addSubview:self.collectionView];
- }
- - (UICollectionView *)collectionView{
- if (!_collectionView) {
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
- flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH-20)/4, 90);
- flowLayout.minimumLineSpacing = 0;
- flowLayout.minimumInteritemSpacing = 0;
- _collectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:flowLayout];
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- _collectionView.showsHorizontalScrollIndicator = NO;
- _collectionView.showsVerticalScrollIndicator = NO;
- _collectionView.scrollEnabled = NO;
- _collectionView.backgroundColor = [UIColor whiteColor];
- [_collectionView registerClass:[KDPSupplyCommentContentCell class] forCellWithReuseIdentifier:NSStringFromClass([KDPSupplyCommentContentCell class])];
- }
- return _collectionView;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- KDPSupplyCommentContentCell *contentCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KDPSupplyCommentContentCell class]) forIndexPath:indexPath];
- [contentCell configCellWithModel:self.dataArray[indexPath.row] indexPath:indexPath];
- return contentCell;
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
- return 1;
- }
- - (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.dataArray.count >= 8 ? 8 : self.dataArray.count;
- }
- - (void)setDataArray:(NSArray *)dataArray{
- _dataArray = dataArray;
- [self.collectionView reloadData];
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- if ([self.delegate respondsToSelector:@selector(commentCollectionView:didSelectIndex:)]) {
- [self.delegate commentCollectionView:collectionView didSelectIndex:indexPath.row];
- }
- }
- @end
- @implementation KDPSupplyCommentContentCell
- {
- UIImageView *_commentImageView;
- UILabel *_commentLabel;
- }
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
-
- [self setUpSubViews];
- [self setSubViewsConstraints];
- }
- return self;
- }
- - (void)setUpSubViews{
- _commentImageView = [[UIImageView alloc] init];
- [self.contentView addSubview:_commentImageView];
-
- _commentLabel = [[UILabel alloc] init];
- _commentLabel.font = FONT_SYS(13);
- _commentLabel.textColor = [UIColor colorWithRGB:0x666666];
- _commentLabel.textAlignment = NSTextAlignmentCenter;
- [self.contentView addSubview:_commentLabel];
- }
- - (void)setSubViewsConstraints{
- [_commentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView.mas_top).offset(30);
- make.size.equalTo(CGSizeMake(20, 35));
- make.centerX.equalTo(self.contentView);
- }];
- [_commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self->_commentImageView.mas_bottom).offset(3);
- make.left.equalTo(self.contentView.mas_left).offset(10);
- make.right.equalTo(self.contentView.mas_right).offset(-10);
- make.centerX.equalTo(self.contentView);
- }];
- }
- - (void)configCellWithModel:(id)model indexPath:(NSIndexPath *)indexpath{
- KDPClassModel *goodModel = (KDPClassModel *)model;
- [_commentImageView sd_setImageWithURL:[NSURL URLWithString:goodModel.icon]placeholderImage:[UIImage imageNamed:placholderImg]];
- _commentLabel.text = goodModel.name;
- }
- @end
|