// // LDModelCollectionCell.m // YouHuiProject // // Created by 小花 on 2018/7/11. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LDModelCollectionCell.h" @interface LDModelCollectionCell() @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, strong) YYLabel *priceLabel; @property (nonatomic, strong) YYLabel *disPrice; @property (nonatomic, strong) UILabel *commissionLabel; @end @implementation LDModelCollectionCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.layer.cornerRadius = 6; [self initSubViews]; } return self; } - (void)initSubViews { [self.contentView addSubview:self.iconView]; [self.contentView addSubview:self.titleLabel]; [self.contentView addSubview:self.priceLabel]; [self.contentView addSubview:self.disPrice]; [self.iconView addSubview:self.commissionLabel]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.right.mas_equalTo(0); make.left.mas_equalTo(0); make.height.mas_equalTo(self.iconView.mas_width); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(0); make.top.mas_equalTo(self.iconView.mas_bottom).mas_offset(Fitsize(10)); }]; [self.disPrice mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(Fitsize(6)); }]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.disPrice.mas_right).mas_offset(3); make.bottom.mas_equalTo(self.disPrice.mas_bottom).mas_offset(-1); }]; [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.mas_offset(0); make.height.mas_equalTo(20); }]; } - (void)setModel:(LDChildGoodModel *)model { _model = model; // [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:Placehold_Img]; [self.iconView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:Placehold_Img options:0 progress:nil completed:nil]; self.titleLabel.text = model.title; self.disPrice.text = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]]; NSString *price=[NSString stringWithFormat:@"%.2f",[model.price floatValue]]; NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:price]; YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@1 color:[UIColor YHColorWithHex:0x999999]]; [attri yy_setTextStrikethrough:decoration range:NSMakeRange(0, price.length)]; attri.yy_color = [UIColor YHColorWithHex:0x999999]; self.priceLabel.attributedText = attri; //预估佣金视图 if (model.commission_price.length > 0) { self.commissionLabel.text = [NSString stringWithFormat:@"预估佣金¥%.2f",[model.commission_price floatValue]]; self.commissionLabel.hidden = NO; }else { self.commissionLabel.hidden = YES; } } #pragma mark --- layzer --- - (UIImageView *)iconView { if (!_iconView) { _iconView = [[UIImageView alloc] init]; _iconView.backgroundColor = [UIColor whiteColor]; _iconView.layer.cornerRadius = 5; _iconView.layer.masksToBounds = YES; } return _iconView; } - (YYLabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[YYLabel alloc] init]; _titleLabel.numberOfLines = 1; _titleLabel.displaysAsynchronously = YES; _titleLabel.textColor = [UIColor YHColorWithHex:0x333333]; _titleLabel.font = [UIFont systemFontOfSize:Fitsize(13)]; } return _titleLabel; } - (YYLabel *)priceLabel { if (!_priceLabel) { _priceLabel = [[YYLabel alloc] init]; _priceLabel.displaysAsynchronously = YES; _priceLabel.textColor = [UIColor YHColorWithHex:0x999999]; _priceLabel.font = [UIFont systemFontOfSize:Fitsize(11)]; _priceLabel.textAlignment = NSTextAlignmentRight; } return _priceLabel; } - (YYLabel *)disPrice { if (!_disPrice) { _disPrice = [[YYLabel alloc] init]; _disPrice.displaysAsynchronously = YES; _disPrice.font = [UIFont systemFontOfSize:Fitsize(14)]; _disPrice.textColor = [UIColor homeRedColor]; } return _disPrice; } - (UILabel *)commissionLabel { if (!_commissionLabel) { _commissionLabel = [[UILabel alloc] init]; _commissionLabel.font = [UIFont systemFontOfSize:11]; _commissionLabel.textColor = [UIColor whiteColor]; _commissionLabel.textAlignment = NSTextAlignmentCenter; _commissionLabel.backgroundColor = [UIColor homeRedColor]; } return _commissionLabel; } @end