// // KBNativeShopCarCollectionCell.m // YouHuiProject // // Created by 小花 on 2018/11/6. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBNativeShopCarCollectionCell.h" @interface KBNativeShopCarCollectionCell () @property (nonatomic, strong) UIImageView *icon; @property (nonatomic, strong) UILabel *title; @property (nonatomic, strong) YYLabel *couple_price; @property (nonatomic, strong) YYLabel *price; @property (nonatomic, strong) YYLabel *endTime; @property (nonatomic, strong) UILabel *couple_label; @end @implementation KBNativeShopCarCollectionCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.contentView.backgroundColor = [UIColor whiteColor]; [self initSubViews]; } return self; } - (void)initSubViews { [self.contentView addSubview:self.icon]; [self.contentView addSubview:self.title]; [self.contentView addSubview:self.couple_price]; [self.contentView addSubview:self.price]; [self.contentView addSubview:self.endTime]; [self.contentView addSubview:self.couple_label]; [self.icon mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.top.mas_equalTo(5); make.width.height.mas_equalTo(78); }]; [self.title mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.icon.mas_right).mas_offset(5); make.top.mas_equalTo(self.icon.mas_top); make.right.mas_equalTo(-10); }]; [self.endTime mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.title.mas_left); make.bottom.mas_equalTo(self.icon.mas_bottom); }]; [self.couple_price mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.title.mas_left); make.top.mas_equalTo(self.title.mas_bottom).mas_offset(10); }]; [self.price mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.couple_price.mas_right).mas_offset(20); make.bottom.mas_equalTo(self.couple_price.mas_bottom); }]; [self.couple_label mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(self.endTime.mas_bottom); make.right.mas_equalTo(-10); make.width.mas_equalTo(60); make.height.mas_equalTo(23); }]; } - (void)setModel:(KBChildGoodModel *)model { _model = model; [self.icon sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil]; self.title.text = model.title; if ([model.is_coupon boolValue]) { NSString *discount_price = [NSString stringWithFormat:@"券后¥%.2f",[model.discount_price floatValue]]; NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:discount_price]; [disAttr yy_setFont:[UIFont systemFontOfSize:12] range:NSMakeRange(0, 3)]; [disAttr yy_setFont:[UIFont systemFontOfSize:16] range:NSMakeRange(3, discount_price.length-3)]; disAttr.yy_color = [UIColor homeRedColor]; self.couple_price.attributedText = disAttr; self.price.text = [NSString stringWithFormat:@"原价¥%@",model.price]; self.couple_label.text = [NSString stringWithFormat:@"%@元券",model.coupon_price]; if (model.coupon_end_time.length > 0) { self.endTime.text = [NSString stringWithFormat:@"%@ 到期",model.coupon_end_time]; } }else { self.couple_price.text = [NSString stringWithFormat:@"¥%@",model.price]; self.couple_price.font = [UIFont systemFontOfSize:16]; } self.couple_label.hidden = ![model.is_coupon boolValue]; self.endTime.hidden = ![model.is_coupon boolValue]; self.price.hidden = ![model.is_coupon boolValue]; } #pragma mark ----- - (UIImageView *)icon { if (!_icon) { _icon = [[UIImageView alloc] init]; _icon.layer.cornerRadius = 4; _icon.backgroundColor = [UIColor yhGrayColor]; } return _icon; } - (UILabel *)title { if (!_title) { _title = [[UILabel alloc] init]; _title.numberOfLines = 2; _title.font = [UIFont systemFontOfSize:12]; } return _title; } - (YYLabel *)couple_price { if (!_couple_price) { _couple_price = [[YYLabel alloc] init]; _couple_price.textColor = [UIColor homeRedColor]; _couple_price.font = [UIFont systemFontOfSize:16]; _couple_price.displaysAsynchronously = YES; } return _couple_price; } - (YYLabel *)price { if (!_price) { _price = [[YYLabel alloc] init]; _price.textColor = [UIColor YHColorWithHex:0xA2A0A0]; _price.font = [UIFont systemFontOfSize:12]; _price.displaysAsynchronously = YES; } return _price; } - (YYLabel *)endTime { if (!_endTime) { _endTime = [[YYLabel alloc] init]; _endTime.font = [UIFont systemFontOfSize:11]; _endTime.textColor = [UIColor YHColorWithHex:0xA2A0A0]; _endTime.displaysAsynchronously = YES; } return _endTime; } - (UILabel *)couple_label { if (!_couple_label) { _couple_label = [[UILabel alloc] init]; _couple_label.textColor = [UIColor whiteColor]; _couple_label.font = [UIFont systemFontOfSize:13]; _couple_label.textAlignment = NSTextAlignmentCenter; _couple_label.backgroundColor = [UIColor homeRedColor]; } return _couple_label; } @end