// // KBGoodHorizontalCollectionCell.m // YouHuiProject // // Created by 小花 on 2018/5/3. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBGoodHorizontalCollectionCell.h" #import "DateFunction.h" @interface KBGoodHorizontalCollectionCell () @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UILabel *endDateLabel; @property (nonatomic, strong) UILabel *endDateLabel2; @property (nonatomic, strong) UILabel *priceLabel; @property (nonatomic, strong) UILabel *disPriceLabel; @property (nonatomic, strong) UIImageView *ticketImg; @property (nonatomic, strong) UILabel *ticketLabel; @property (nonatomic, strong) UILabel *outTimeLabel; @property (nonatomic, strong) UIButton *sameButton; @property (nonatomic, strong) UILabel *ticketType; @property (nonatomic, strong) UIImageView *outDateImg; @property (nonatomic, strong) UIButton *cancelCollection; @property (nonatomic, strong) UILabel *commissionLabel; @end @implementation KBGoodHorizontalCollectionCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor whiteColor]; [self initSubView]; } return self; } - (void)initSubView { [self.contentView addSubview:self.iconView]; [self.contentView addSubview:self.titleLabel]; [self.contentView addSubview:self.endDateLabel]; [self.contentView addSubview:self.endDateLabel2]; [self.contentView addSubview:self.priceLabel]; [self.contentView addSubview:self.disPriceLabel]; [self.contentView addSubview:self.ticketImg]; [self addSubview:self.cancelCollection]; [self.ticketImg addSubview:self.ticketType]; [self.ticketImg addSubview:self.ticketLabel]; [self.iconView addSubview:self.outTimeLabel]; [self.outTimeLabel addSubview:self.outDateImg]; [self.iconView addSubview:self.commissionLabel]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.width.height.mas_equalTo(100); make.top.mas_equalTo(10); }]; [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.height.mas_equalTo(20); }]; [self.outTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.bottom.mas_equalTo(0); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(10); make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10); make.right.mas_equalTo(-10); }]; [self.endDateLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(8); make.height.mas_equalTo(15); // make.right.mas_equalTo(-10); }]; [self.endDateLabel2 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(8); make.height.mas_equalTo(15); // make.right.mas_equalTo(-10); }]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.bottom.mas_equalTo(-10); }]; [self.disPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.priceLabel.mas_right).mas_offset(5); make.centerY.mas_equalTo(self.priceLabel.mas_centerY); }]; [self.ticketImg mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.bottom.mas_equalTo(self.iconView.mas_bottom); make.width.mas_equalTo(64); make.height.mas_equalTo(14); }]; [self.ticketType mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.bottom.mas_equalTo(0); make.width.mas_equalTo(20); }]; [self.ticketLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(20); make.top.bottom.right.mas_equalTo(0); }]; [self.outDateImg mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(60); make.height.mas_equalTo(38); make.center.mas_equalTo(self.outTimeLabel.center); }]; [self.cancelCollection mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.centerY.mas_equalTo(self.mas_centerY); make.width.height.mas_equalTo(30); }]; } - (void)setCollectionModel:(KBCollectionModel *)collectionModel { _collectionModel = collectionModel; //头像、标题 [_iconView sd_setImageWithURL:[NSURL URLWithString:collectionModel.img]]; self.titleLabel.text = collectionModel.title; self.outTimeLabel.hidden = ![collectionModel.isExpire isEqualToString:@"1"]; //过期时间 if ([collectionModel.isExpire isEqualToString:@"2"]) { int endCount = [DateFunction intervalSinceNow:collectionModel.coupon_end_time]; NSString *endDateStr = [NSString stringWithFormat:@"%d天后过期",endCount]; CGSize size = [PublicFunction getAutoWidthWith:endDateStr andSize:CGSizeMake(1000, 15) andFont:11]; [self.endDateLabel2 mas_updateConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(size.width+20); }]; self.endDateLabel2.text = endDateStr; self.endDateLabel.hidden = YES; self.endDateLabel2.hidden = NO; }else { NSString *endText = [NSString stringWithFormat:@"到期时间:%@",collectionModel.coupon_end_time]; self.endDateLabel.text = endText; self.endDateLabel2.hidden = YES; self.endDateLabel.hidden = NO; } //折扣还是券 self.endDateLabel2.hidden = ![collectionModel.is_coupon boolValue]; self.endDateLabel.hidden = ![collectionModel.is_coupon boolValue]; NSString *type = [collectionModel.is_coupon boolValue]?@"券后":@"折后"; NSString *price = [NSString stringWithFormat:@"%@¥%.2f",type,[collectionModel.discount_price floatValue]]; NSMutableAttributedString *priceAttr = [[NSMutableAttributedString alloc] initWithString:price]; [priceAttr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11] range:NSMakeRange(0, 3)]; self.priceLabel.attributedText = priceAttr; self.ticketType.text = [collectionModel.is_coupon boolValue]?@"券":@"折"; self.ticketImg.hidden = ![collectionModel.is_coupon boolValue]; //价钱 NSString *disPrice = [NSString stringWithFormat:@"¥%.2f",[collectionModel.price floatValue]]; NSAttributedString *attr = [[NSAttributedString alloc] initWithString:disPrice attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:[UIColor YHColorWithHex:0x999999], NSStrikethroughColorAttributeName:[UIColor YHColorWithHex:0x999999], NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle|NSUnderlinePatternSolid)}]; self.disPriceLabel.attributedText = attr; if ([collectionModel.is_coupon boolValue]) { self.ticketLabel.text = [NSString stringWithFormat:@"%@元",collectionModel.coupon_price]; }else { self.ticketLabel.text = [NSString stringWithFormat:@"%@折",collectionModel.coupon_price]; } } - (void)cancelAction { if (self.cancelBlock) { self.cancelBlock(); } } #pragma mark ------------------ - (UIImageView *)iconView { if (!_iconView) { _iconView = [[UIImageView alloc] init]; _iconView.backgroundColor = [UIColor yhGrayColor]; } return _iconView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.textColor = [UIColor YHColorWithHex:0x444444]; _titleLabel.font = [UIFont systemFontOfSize:14]; _titleLabel.numberOfLines = 2; } return _titleLabel; } - (UILabel *)endDateLabel { if (!_endDateLabel) { _endDateLabel = [[UILabel alloc] init]; _endDateLabel.textColor = [UIColor YHColorWithHex:0x999999]; _endDateLabel.font = [UIFont systemFontOfSize:11]; } return _endDateLabel; } - (UILabel *)endDateLabel2 { if (!_endDateLabel2) { _endDateLabel2 = [[UILabel alloc] init]; _endDateLabel2.textColor = [UIColor YHColorWithHex:0x999999]; _endDateLabel2.font = [UIFont systemFontOfSize:11]; _endDateLabel2.textAlignment = NSTextAlignmentCenter; _endDateLabel2.layer.cornerRadius = 7; _endDateLabel2.layer.masksToBounds = YES; _endDateLabel2.backgroundColor = [UIColor homeRedColor]; _endDateLabel2.textColor = [UIColor whiteColor]; } return _endDateLabel2; } - (UILabel *)priceLabel { if (!_priceLabel) { _priceLabel = [[UILabel alloc] init]; _priceLabel.font = [UIFont systemFontOfSize:15]; _priceLabel.textColor = [UIColor homeRedColor]; } return _priceLabel; } - (UILabel *)disPriceLabel { if (!_disPriceLabel) { _disPriceLabel = [[UILabel alloc] init]; _disPriceLabel.font = [UIFont systemFontOfSize:11]; _disPriceLabel.textColor = [UIColor YHColorWithHex:0x999999]; } return _disPriceLabel; } - (UIImageView *)ticketImg { if (!_ticketImg) { _ticketImg = [[UIImageView alloc] init]; _ticketImg.image = [UIImage imageNamed:@"quan_bg"]; } return _ticketImg; } - (UILabel *)ticketLabel { if (!_ticketLabel) { _ticketLabel = [[UILabel alloc] init]; _ticketLabel.textColor = [UIColor whiteColor]; _ticketLabel.font = [UIFont systemFontOfSize:14]; _ticketLabel.textAlignment = NSTextAlignmentCenter; _ticketLabel.font = [UIFont systemFontOfSize:10]; _ticketLabel.textAlignment = NSTextAlignmentCenter; _ticketLabel.textColor = [UIColor whiteColor]; } return _ticketLabel; } - (UILabel *)outTimeLabel { if (!_outTimeLabel) { _outTimeLabel = [[UILabel alloc] init]; _outTimeLabel.textAlignment = NSTextAlignmentCenter; _outTimeLabel.textColor = [UIColor whiteColor]; _outTimeLabel.font = [UIFont systemFontOfSize:12]; _outTimeLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6]; _outTimeLabel.hidden = YES; } return _outTimeLabel; } - (UILabel *)ticketType { if (!_ticketType) { _ticketType = [[UILabel alloc] init]; _ticketType.font = [UIFont systemFontOfSize:10]; _ticketType.textAlignment = NSTextAlignmentCenter; _ticketType.textColor = [UIColor whiteColor]; } return _ticketType; } - (UIImageView *)outDateImg { if (!_outDateImg) { _outDateImg = [[UIImageView alloc] init]; _outDateImg.image = [UIImage imageNamed:@"outDateImg"]; _outDateImg.backgroundColor = [UIColor clearColor]; } return _outDateImg; } - (UIButton *)cancelCollection { if (!_cancelCollection) { _cancelCollection = [UIButton buttonWithType:UIButtonTypeCustom]; [_cancelCollection setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal]; [_cancelCollection addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside]; } return _cancelCollection; } - (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