// // KDPLiveLeftTableViewCell.m // KuDianProject // // Created by admin on 2019/7/9. // Copyright © 2019 KDP. All rights reserved. // #import "KDPLiveLeftTableViewCell.h" #import "KDPLiveListModel.h" @implementation KDPLiveLeftTableViewCell { UILabel *_timeLabel; UIButton *_checkOrderBtn; UIImageView *_iconImageView; UILabel *_goodCountLabel; UILabel *_goodDetailLabel; UILabel *_orderLabel; UILabel *_orderDetailLabel; UILabel *_investLabel; UILabel *_investDetailLabel; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setContentView]; [self setContentViewConstraints]; } return self; } - (void)setContentView{ self.contentView.backgroundColor = [UIColor whiteColor]; _timeLabel = [[UILabel alloc] init]; _timeLabel.font = FONT_SYS(12); _timeLabel.textColor = [UIColor colorWithHex:0x333333]; _timeLabel.text = @"直播时间:2019-07-03 20:00:00"; [self.contentView addSubview:_timeLabel]; _checkOrderBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_checkOrderBtn setTitle:@"查看订单>" forState:UIControlStateNormal]; [_checkOrderBtn setTitleColor:[UIColor colorWithHex:0xFF235F] forState:UIControlStateNormal]; _checkOrderBtn.titleLabel.font = FONT_SYS(12); [_checkOrderBtn addTarget:self action:@selector(checkOrderAction:) forControlEvents:UIControlEventTouchUpInside]; _checkOrderBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; _checkOrderBtn.showsTouchWhenHighlighted = NO; [self.contentView addSubview:_checkOrderBtn]; _iconImageView = [[UIImageView alloc] init]; [self.contentView addSubview:_iconImageView]; _goodCountLabel = [[UILabel alloc] init]; _goodCountLabel.textColor = [UIColor colorWithHex:0x333333]; _goodCountLabel.font = FONT_SYS(20); _goodCountLabel.text = @"100"; _goodCountLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:_goodCountLabel]; _goodDetailLabel = [[UILabel alloc] init]; _goodDetailLabel.textColor = [UIColor colorWithHex:0x666666]; _goodDetailLabel.font = FONT_SYS(12); _goodDetailLabel.textAlignment = NSTextAlignmentCenter; _goodDetailLabel.text = @"上架商品数"; [self.contentView addSubview:_goodDetailLabel]; _orderLabel = [[UILabel alloc] init]; _orderLabel.textColor = [UIColor colorWithHex:0x333333]; _orderLabel.font = FONT_SYS(20); _orderLabel.text = @"100"; _orderLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:_orderLabel]; _orderDetailLabel = [[UILabel alloc] init]; _orderDetailLabel.textColor = [UIColor colorWithHex:0x666666]; _orderDetailLabel.font = FONT_SYS(12); _orderDetailLabel.textAlignment = NSTextAlignmentCenter; _orderDetailLabel.text = @"订单数"; [self.contentView addSubview:_orderDetailLabel]; _investLabel = [[UILabel alloc] init]; _investLabel.textColor = [UIColor colorWithHex:0x333333]; _investLabel.font = FONT_SYS(20); _investLabel.text = @"100"; _investLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:_investLabel]; _investDetailLabel = [[UILabel alloc] init]; _investDetailLabel.textColor = [UIColor colorWithHex:0x666666]; _investDetailLabel.font = FONT_SYS(12); _investDetailLabel.textAlignment = NSTextAlignmentCenter; _investDetailLabel.text = @"预估收益"; [self.contentView addSubview:_investDetailLabel]; } - (void)setContentViewConstraints{ self.backgroundColor = [UIColor clearColor]; [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(UIEdgeInsetsMake(0, 10, 6, 10)); }]; self.contentView.layer.cornerRadius = 6; self.contentView.layer.masksToBounds = YES; [_checkOrderBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView.mas_top).offset(7); make.size.equalTo(CGSizeMake(70, 17)); make.right.equalTo(self.contentView.mas_right).offset(-9); }]; [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.mas_left).offset(8); make.centerY.equalTo(self->_checkOrderBtn); make.right.equalTo(self->_checkOrderBtn.mas_left).offset(-10); }]; [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self->_timeLabel.mas_left); make.top.equalTo(self->_checkOrderBtn.mas_bottom).offset(18); make.size.equalTo(CGSizeMake(80, 80)); }]; [_goodCountLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self->_iconImageView.mas_right); make.top.equalTo(self->_iconImageView.mas_top).offset(15); make.width.equalTo(self->_orderLabel.mas_width); }]; [_goodDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self->_goodCountLabel); make.top.equalTo(self->_goodCountLabel.mas_bottom).offset(6); make.width.equalTo(self->_orderDetailLabel); }]; [_orderLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self->_goodCountLabel.mas_right); make.top.equalTo(self->_iconImageView.mas_top).offset(15); make.width.equalTo(self->_investLabel.mas_width); }]; [_orderDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self->_goodDetailLabel.mas_right); make.top.equalTo(self->_orderLabel.mas_bottom).offset(6); make.width.equalTo(self->_investDetailLabel); }]; [_investLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self->_orderLabel.mas_right); make.top.equalTo(self->_iconImageView.mas_top).offset(15); make.width.equalTo(self->_goodCountLabel); make.right.equalTo(self.contentView.mas_right); }]; [_investDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self->_orderDetailLabel.mas_right); make.top.equalTo(self->_goodCountLabel.mas_bottom).offset(6); make.width.equalTo(self->_goodDetailLabel); make.right.equalTo(self.contentView.mas_right); }]; [self.contentView layoutIfNeeded]; // 虚线 CAShapeLayer *dotteShapeLayer = [CAShapeLayer layer]; CGMutablePathRef dotteshapePath = CGPathCreateMutable(); // 设置虚线颜色 [dotteShapeLayer setStrokeColor:[UIColor colorWithHex:0xC5C5C5].CGColor]; dotteShapeLayer.lineWidth = 0.3f; NSArray *dottehShapeArr = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4], nil]; [dotteShapeLayer setLineDashPattern:dottehShapeArr]; CGPathMoveToPoint(dotteshapePath, NULL, _timeLabel.left,_timeLabel.bottom+5); CGPathAddLineToPoint(dotteshapePath, NULL, _checkOrderBtn.right, _timeLabel.bottom+5); [dotteShapeLayer setPath:dotteshapePath]; CGPathRelease(dotteshapePath); [self.contentView.layer addSublayer:dotteShapeLayer]; } - (void)configWithViewModel:(id)viewModel indexpath:(NSIndexPath *)indexPath{ KDPLiveListModel *model = (KDPLiveListModel*)viewModel; _timeLabel.text = [NSString stringWithFormat:@"直播时间:%@",model.show_time]; _goodCountLabel.text = model.goods_num; _orderLabel.text = model.order_num; [_iconImageView sd_setImageWithURL:[NSURL URLWithString:model.show_img]placeholderImage:[UIImage imageNamed:placholderImg]]; _investLabel.text = model.pre_rebate; } - (void)checkOrderAction:(UIButton *)sender{ if (self.orderClickBlock) { self.orderClickBlock(sender); } } @end