// // LZMNineNineTableViewCell.m // YouHuiProject // // Created by xiaoxi on 2018/1/17. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LZMNineNineTableViewCell.h" #import "LZMCollectionView.h" static NSString *const cellID = @"YHNineNineTableCollectionViewCell"; @implementation YHNineNineTableCollectionViewCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } - (void)initSubviews { [self.contentView.layer addSublayer:self.pictureLayer]; [self.contentView addSubview:self.topLabel]; [self.contentView addSubview:self.bottomLabel]; [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView); make.top.equalTo(self.contentView).offset(FITSIZE((120+5))); make.right.equalTo(self.contentView); }]; [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView); make.bottom.equalTo(self.contentView).offset(-FITSIZE(10)); }]; } - (void)setModel:(YHNineNineMiddleCollectionModel *)model { _model = model; [self.pictureLayer yy_setImageWithURL:[NSURL URLWithString:model.img] placeholder:Placehold_Img options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation completion:nil]; NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init]; [paraStyle setLineSpacing:5]; NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:model.title attributes:@{NSParagraphStyleAttributeName:paraStyle}]; self.topLabel.attributedText = attString; self.bottomLabel.text = [NSString stringWithFormat:@"¥ %@", model.discount_price]; } #pragma mark -lazy - (CALayer *)pictureLayer { if (!_pictureLayer) { _pictureLayer = [CALayer layer]; _pictureLayer.backgroundColor = [UIColor clearColor].CGColor; _pictureLayer.frame = CGRectMake(0, 0, FITSIZE(120), FITSIZE(120)); _pictureLayer.cornerRadius = 3; } return _pictureLayer; } - (UILabel *)topLabel { if (!_topLabel) { _topLabel = [[UILabel alloc] init]; _topLabel.backgroundColor = [UIColor clearColor]; _topLabel.textColor = [UIColor YHColorWithHex:0x444444]; _topLabel.font = [UIFont systemFontOfSize:FITSIZE(12)]; _topLabel.numberOfLines = 2; } return _topLabel; } - (UILabel *)bottomLabel { if (!_bottomLabel) { _bottomLabel = [[UILabel alloc] init]; _bottomLabel.backgroundColor = [UIColor clearColor]; _bottomLabel.textColor = [UIColor YHColorWithHex:0xff2420]; _bottomLabel.font = [UIFont systemFontOfSize:FITSIZE(13)]; } return _bottomLabel; } @end @interface LZMNineNineTableViewCell () @end @implementation LZMNineNineTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self initSubviews]; } return self; } - (void)initSubviews { [self.contentView.layer addSublayer:self.bottomLine]; [self.contentView addSubview:self.leftLabel]; [self.contentView addSubview:self.rightLabel]; [self.contentView addSubview:self.rightImageView]; [self.contentView addSubview:self.collectionView]; [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(FITSIZE(15)); make.top.equalTo(self.contentView).offset(FITSIZE(12)); }]; [self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView).offset(-FITSIZE(15)); make.centerY.equalTo(self.leftLabel).offset(1); make.size.mas_equalTo(CGSizeMake(FITSIZE(20), FITSIZE(20))); }]; [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.rightImageView.mas_left); make.centerY.equalTo(self.leftLabel); }]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView); make.top.equalTo(self.leftLabel.mas_bottom).offset(FITSIZE(9)); make.right.equalTo(self.contentView); make.bottom.equalTo(self.contentView); }]; } - (void)setModel:(YHNineNineMiddleModel *)model { _model = model; self.leftLabel.text = model.title.name; self.rightLabel.text = [NSString stringWithFormat:@"共%@件", model.title.num]; [self.collectionView reloadData]; } #pragma mark - collectionView - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { NSArray *arr = self.model.list; return arr.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { YHNineNineTableCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath]; YHNineNineMiddleCollectionModel *model = self.model.list[indexPath.item]; cell.model = model; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if ([self.delegate respondsToSelector:@selector(yh_NineNineTableViewCellDidSelectItem:)]) { [self.delegate yh_NineNineTableViewCellDidSelectItem:self.model]; } } #pragma mark - lazy - (CALayer *)bottomLine { if (!_bottomLine) { _bottomLine = [CALayer layer]; _bottomLine.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor; _bottomLine.frame = CGRectMake(0, FITSIZE(235), kScreenWidth, FITSIZE(5)); } return _bottomLine; } - (UILabel *)leftLabel { if (!_leftLabel) { _leftLabel = [[UILabel alloc] init]; _leftLabel.backgroundColor = [UIColor clearColor]; _leftLabel.textColor = [UIColor YHColorWithHex:0x222222]; _leftLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(14)]; } return _leftLabel; } - (UILabel *)rightLabel { if (!_rightLabel) { _rightLabel = [[UILabel alloc] init]; _rightLabel.backgroundColor = [UIColor clearColor]; _rightLabel.textColor = [UIColor YHColorWithHex:0x999999]; _rightLabel.font = [UIFont systemFontOfSize:FITSIZE(12)]; _rightLabel.textAlignment = NSTextAlignmentRight; } return _rightLabel; } - (UIImageView *)rightImageView { if (!_rightImageView) { _rightImageView = [[UIImageView alloc] init]; _rightImageView.backgroundColor = [UIColor clearColor]; _rightImageView.image = [UIImage imageNamed:@"goto"]; } return _rightImageView; } - (UICollectionView *)collectionView { if (!_collectionView) { UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.itemSize = CGSizeMake(FITSIZE(120), FITSIZE(191.5)); flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; flowLayout.minimumLineSpacing = FITSIZE(10); flowLayout.minimumInteritemSpacing = FITSIZE(0); flowLayout.sectionInset = UIEdgeInsetsMake(0, FITSIZE(15), 0, FITSIZE(15)); _collectionView = [[LZMCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; _collectionView.contentInset = UIEdgeInsetsZero; _collectionView.showsHorizontalScrollIndicator = NO; _collectionView.delegate = self; _collectionView.dataSource = self; [_collectionView registerClass:[YHNineNineTableCollectionViewCell class] forCellWithReuseIdentifier:cellID]; } return _collectionView; } @end