// // KBOnePicCell.m // YouHuiProject // // Created by 小花 on 2018/1/17. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBOnePicCell.h" @interface KBOnePicCell () @property (nonatomic, strong) UIImageView *imgView; @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UILabel *countLabel; @property (nonatomic, strong) UILabel *desLabel; @property (nonatomic, strong) UILabel *priceLabel; @property (nonatomic, strong) UIImageView *ticketImg; @property (nonatomic, strong) UILabel *ticketPrice; @property (nonatomic, strong) UILabel *saleCount; @property (nonatomic, strong) UIImageView *ticketNumber; @property (nonatomic, strong) UIView *line; @property (nonatomic, strong) UILabel *zheKou; @property (nonatomic, strong) UILabel *typeLabel; @property (nonatomic, strong) UIImageView *isNew; @property (nonatomic, strong) UILabel *numLabel; @end @implementation KBOnePicCell + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *cellID = nil; cellID = NSStringFromClass([self class]); KBOnePicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[KBOnePicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } return cell; } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.selectionStyle = UITableViewCellSelectionStyleNone; [self initSubViews]; } return self; } - (void)initSubViews { [self.contentView addSubview:self.imgView]; [self.imgView addSubview:self.isNew]; [self.contentView addSubview:self.titleLabel]; [self.contentView addSubview:self.countLabel]; [self.contentView addSubview:self.desLabel]; [self.contentView addSubview:self.priceLabel]; [self.contentView addSubview:self.saleCount]; [self.contentView addSubview:self.ticketImg]; [self.ticketImg addSubview:self.typeLabel]; [self.contentView addSubview:self.ticketPrice]; [self.contentView addSubview:self.ticketNumber]; [self.contentView addSubview:self.line]; [self.ticketNumber addSubview:self.zheKou]; [self.imgView addSubview:self.numLabel]; [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.mas_equalTo(0); make.width.height.mas_equalTo(Fitsize(152)); }]; [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.mas_equalTo(0); make.height.mas_equalTo(20); }]; [self.isNew mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(10); make.width.mas_equalTo(45); make.height.mas_equalTo(19); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.imgView.mas_right).mas_offset(10); make.top.mas_equalTo(10); make.right.mas_equalTo(-10); }]; [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(7); make.right.mas_equalTo(self.titleLabel.mas_right); }]; [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.top.mas_equalTo(self.countLabel.mas_bottom).mas_offset(7); make.right.mas_equalTo(self.titleLabel.mas_right); }]; [self.ticketImg mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.bottom.mas_equalTo(Fitsize(-20)); make.width.mas_equalTo(34); make.height.mas_equalTo(18); }]; [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.bottom.mas_equalTo(0); }]; [self.ticketPrice mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.ticketImg.mas_right).mas_offset(5); make.centerY.mas_equalTo(self.ticketImg.mas_centerY); }]; [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.centerY.mas_equalTo(self.ticketImg.mas_centerY); make.width.mas_equalTo(64); make.height.mas_equalTo(22); }]; [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.left.right.mas_equalTo(0); }]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.bottom.mas_equalTo(self.ticketImg.mas_top).mas_offset(-10); }]; [self.saleCount mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.centerY.mas_equalTo(self.priceLabel.mas_centerY); }]; [self.line mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.bottom.mas_equalTo(-5); make.height.mas_equalTo(0.5); make.right.mas_equalTo(-5); }]; } - (void)setModel:(KBChildGoodModel *)model { _model = model; [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:Placehold_Img]; self.titleLabel.text = model.title; self.priceLabel.text = [NSString stringWithFormat:@"淘宝价 ¥%.2f",[model.price floatValue]]; self.saleCount.text = [NSString stringWithFormat:@"月销%@",model.volume]; self.ticketPrice.text = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]]; //折后价 if (model.is_coupon) { self.typeLabel.text = @"券后价"; self.zheKou.text = [NSString stringWithFormat:@"%@元券",model.coupon_price]; }else { self.typeLabel.text = @"折后价"; self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price]; } if ([model.type isEqualToString:@"1"]) { self.numLabel.hidden = NO; self.numLabel.text = [NSString stringWithFormat:@"共%@件",model.coupon_surplus]; }else { self.numLabel.hidden = YES; } self.isNew.hidden = ![model.is_new boolValue]; } #pragma mark =============== layzer ================= - (UIImageView *)imgView { if (!_imgView) { _imgView = [[UIImageView alloc] init]; _imgView.backgroundColor = [UIColor yhGrayColor]; } return _imgView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.text = @"哈密瓜哈密瓜哈密瓜哈密瓜哈密瓜"; _titleLabel.font = [UIFont systemFontOfSize:15]; _titleLabel.numberOfLines = 2; _titleLabel.textColor = [UIColor YHColorWithHex:0x222222]; } return _titleLabel; } - (UILabel *)countLabel { if (!_countLabel) { _countLabel = [[UILabel alloc] init]; _countLabel.font = [UIFont systemFontOfSize:15]; _countLabel.textColor = [UIColor YHColorWithHex:0x222222]; } return _countLabel; } - (UILabel *)desLabel { if (!_desLabel) { _desLabel = [[UILabel alloc] init]; _desLabel.textColor = [UIColor homeRedColor]; _desLabel.font = [UIFont systemFontOfSize:13]; } return _desLabel; } - (UILabel *)priceLabel { if (!_priceLabel) { _priceLabel = [[UILabel alloc] init]; _priceLabel.font = [UIFont systemFontOfSize:12]; _priceLabel.textColor = [UIColor YHColorWithHex:0x999999]; } return _priceLabel; } - (UILabel *)saleCount { if (!_saleCount) { _saleCount = [[UILabel alloc] init]; _saleCount.font = [UIFont systemFontOfSize:12]; _saleCount.textColor = [UIColor YHColorWithHex:0x999999]; _saleCount.textAlignment = NSTextAlignmentRight; } return _saleCount; } - (UIImageView *)ticketImg { if (!_ticketImg) { _ticketImg = [[UIImageView alloc] init]; _ticketImg.image = [UIImage imageNamed:@"sale"]; } return _ticketImg; } - (UILabel *)ticketPrice { if (!_ticketPrice) { _ticketPrice = [[UILabel alloc] init]; _ticketPrice.textColor = [UIColor homeRedColor]; _ticketPrice.font = [UIFont boldSystemFontOfSize:17]; } return _ticketPrice; } - (UIImageView *)ticketNumber { if (!_ticketNumber) { _ticketNumber = [[UIImageView alloc] init]; _ticketNumber.image = [UIImage imageNamed:@"discount"]; } return _ticketNumber; } - (UILabel *)zheKou { if (!_zheKou) { _zheKou = [[UILabel alloc] init]; _zheKou.textColor = [UIColor whiteColor]; _zheKou.textAlignment = NSTextAlignmentCenter; _zheKou.font = [UIFont systemFontOfSize:13]; _zheKou.backgroundColor = [UIColor clearColor]; } return _zheKou; } - (UILabel *)typeLabel { if (!_typeLabel) { _typeLabel = [[UILabel alloc] init]; _typeLabel.textColor = [UIColor whiteColor]; _typeLabel.font = [UIFont systemFontOfSize:10]; _typeLabel.textAlignment = NSTextAlignmentCenter; } return _typeLabel; } - (UIView *)line { if (!_line) { _line = [[UIView alloc] init]; _line.backgroundColor = [UIColor YHColorWithHex:0xcccccc]; } return _line; } - (UIImageView *)isNew { if (!_isNew) { _isNew = [[UIImageView alloc] init]; _isNew.image = [UIImage imageNamed:@"new"]; } return _isNew; } - (UILabel *)numLabel { if (!_numLabel) { _numLabel = [[UILabel alloc] init]; _numLabel.textColor = [UIColor whiteColor]; _numLabel.textAlignment = NSTextAlignmentCenter; _numLabel.font = [UIFont systemFontOfSize:11]; _numLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6]; } return _numLabel; } @end