// // KBScrollChildCollectionViewCell.m // YouHuiProject // // Created by xiaoxi on 2018/1/17. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBScrollChildCollectionViewCell.h" @implementation KBScrollChildCollectionViewCell - (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.middleLabel]; [self.contentView addSubview:self.bottomLabel]; [self.contentView addSubview:self.priceLabel]; [_topLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(FITSIZE(10)); make.top.equalTo(self.contentView).offset(FITSIZE(195)); make.right.equalTo(self.contentView).offset(-FITSIZE(10)); }]; [_middleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_topLabel); make.top.equalTo(_topLabel.mas_bottom).offset(FITSIZE(15)); make.right.equalTo(_topLabel); }]; [_bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_middleLabel); make.top.equalTo(_middleLabel.mas_bottom).offset(FITSIZE(15)); make.right.equalTo(_middleLabel); }]; [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView).offset(-FITSIZE(10)); make.centerY.equalTo(_bottomLabel); }]; } - (void)setModel:(KBChildGoodModel *)model { _model = model; [self.pictureLayer yy_setImageWithURL:[NSURL URLWithString:model.img] placeholder:Placehold_Img options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation completion:nil]; NSMutableAttributedString *topAttStr = [[NSMutableAttributedString alloc] initWithString:model.title]; NSTextAttachment *attach = [[NSTextAttachment alloc] init]; if ([model.freeShipping boolValue]) { attach.image = [UIImage imageNamed:@"Rectangle"]; attach.bounds = CGRectMake(0, -1, 26, 13); [topAttStr insertAttributedString:[NSAttributedString attributedStringWithAttachment:attach] atIndex:0]; } self.topLabel.attributedText = topAttStr; self.middleLabel.text = [NSString stringWithFormat:@"月销 %@", model.volume]; NSAttributedString *bottomAttStr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"原价 ¥%.2f", model.price.floatValue] attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}]; self.bottomLabel.attributedText = bottomAttStr; self.priceLabel.text = [NSString stringWithFormat:@"¥ %.2f", model.discount_price.floatValue]; } #pragma mark - lazy - (CALayer *)pictureLayer { if (!_pictureLayer) { _pictureLayer = [CALayer layer]; _pictureLayer.backgroundColor = [UIColor clearColor].CGColor; _pictureLayer.frame = CGRectMake(0, 0, FITSIZE(185), FITSIZE(185)); } return _pictureLayer; } - (UILabel *)topLabel { if (!_topLabel) { _topLabel = [[UILabel alloc] init]; _topLabel.backgroundColor = [UIColor clearColor]; _topLabel.textColor = [UIColor YHColorWithHex:0x444444]; _topLabel.font = [UIFont systemFontOfSize:FITSIZE(14)]; } return _topLabel; } - (UILabel *)middleLabel { if (!_middleLabel) { _middleLabel = [[UILabel alloc] init]; _middleLabel.backgroundColor = [UIColor clearColor]; _middleLabel.textColor = [UIColor YHColorWithHex:0x999999]; _middleLabel.font = [UIFont systemFontOfSize:FITSIZE(10)]; } return _middleLabel; } - (UILabel *)bottomLabel { if (!_bottomLabel) { _bottomLabel = [[UILabel alloc] init]; _bottomLabel.backgroundColor = [UIColor clearColor]; _bottomLabel.textColor = [UIColor YHColorWithHex:0x888888]; _bottomLabel.font = [UIFont systemFontOfSize:FITSIZE(12)]; } return _bottomLabel; } - (UILabel *)priceLabel { if (!_priceLabel) { _priceLabel = [[UILabel alloc] init]; _priceLabel.backgroundColor = [UIColor clearColor]; _priceLabel.textColor = [UIColor YHColorWithHex:0xff2420]; _priceLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(18)]; } return _priceLabel; } @end