// // KBModuleCollectionCell.m // YouHuiProject // // Created by 小花 on 2018/7/4. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBModuleCollectionCell.h" @interface KBModuleCollectionCell() @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UILabel *priceLabel; @property (nonatomic, strong) UILabel *disPrice; @property (nonatomic, strong) UILabel *commissionLabel; @end @implementation KBModuleCollectionCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.layer.cornerRadius = 6; self.layer.masksToBounds = YES; [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.left.right.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:(KBChildGoodModel *)model { _model = model; [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:Placehold_Img]; 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]; [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, price.length)]; [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor YHColorWithHex:0x999999] range:NSMakeRange(0, price.length)]; self.priceLabel.attributedText = attri; } #pragma mark --- layzer --- - (UIImageView *)iconView { if (!_iconView) { _iconView = [[UIImageView alloc] init]; _iconView.backgroundColor = [UIColor yhGrayColor]; _iconView.layer.cornerRadius = 5; _iconView.layer.masksToBounds = YES; } return _iconView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.numberOfLines = 1; _titleLabel.textColor = [UIColor YHColorWithHex:0x333333]; _titleLabel.font = [UIFont systemFontOfSize:Fitsize(12)]; } return _titleLabel; } - (UILabel *)priceLabel { if (!_priceLabel) { _priceLabel = [[UILabel alloc] init]; _priceLabel.textColor = [UIColor YHColorWithHex:0x999999]; _priceLabel.font = [UIFont systemFontOfSize:Fitsize(11)]; } return _priceLabel; } - (UILabel *)disPrice { if (!_disPrice) { _disPrice = [[UILabel alloc] init]; _disPrice.font = [UIFont systemFontOfSize:Fitsize(15)]; _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 changeColor]; _commissionLabel.hidden = YES; } return _commissionLabel; } @end