// // ASCouponListCell.m // Asteria // // Created by iOS on 2023/6/25. // #import "ASCouponListCell.h" @interface ASCouponListCell () @property (nonatomic, strong) UIView *bgV; @property (nonatomic, strong) UIImageView *bg1; @property (nonatomic, strong) UIImageView *bg2; @property (nonatomic, strong) UIImageView *ln1; @property (nonatomic, strong) UIImageView *ln2; @property (nonatomic, strong) UIImageView *sep; @property (nonatomic, strong) UILabel *titleLb; @property (nonatomic, strong) UILabel *ruleLb; @property (nonatomic, strong) UILabel *dateLb; @property (nonatomic, strong) UILabel *cpLb; @property (nonatomic, strong) UILabel *codeTitleLb; @property (nonatomic, strong) UILabel *codeLb; @property (nonatomic, strong) UIButton *cpBt; @property (nonatomic, strong) UILabel *usedLb; @end @implementation ASCouponListCell - (void)setVipData:(ASVipCouponModel *)model { self.titleLb.text = [NSString stringWithFormat:@"%@", model.title];//@"$10 off"; self.ruleLb.text = @""; self.dateLb.text = [NSString stringWithFormat:@"%@", model.desc]; self.codeLb.text = model.code; [self setStatus:model.used.integerValue != 0 ]; } - (void)setData:(ASCouponsModel *)model { self.titleLb.text = [NSString stringWithFormat:@"%@", model.title];//@"$10 off"; self.ruleLb.text = [NSString stringWithFormat:@"%@", model.desc]; self.dateLb.text = [NSString stringWithFormat:@"DATE:%@", model.activity_time]; self.codeLb.text = model.code; [self setStatus:model.used.integerValue != 1 ]; } - (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 loadSubVs]; } return self; } - (void)setVipCouponStyle { self.codeLb.hidden = true; self.codeTitleLb.text = @"COUPONS"; self.cpLb.text = @"GET"; self.usedLb.text = @"GOT"; } - (void)setGiftCardStyle { self.codeLb.hidden = true; self.codeTitleLb.text = @"GIFTCARD"; self.cpLb.text = @"USE"; } - (void)setStatus:(BOOL)isUsed { self.usedLb.hidden = !isUsed; self.cpBt.hidden = isUsed; self.titleLb.textColor = isUsed ? _DBDBDB : Col_000; self.ruleLb.textColor = isUsed ? _DBDBDB : _043632; self.dateLb.textColor = isUsed ? _DBDBDB : _128273; self.codeTitleLb.textColor = isUsed ? Col_FFF : _043632; self.codeLb.textColor = isUsed ? Col_FFF : _043632; self.bg1.image = [UIImage imageNamed:isUsed ? @"uc_coupon_colorBg1_sel" : @"uc_coupon_colorBg1"]; self.bg2.image = [UIImage imageNamed:isUsed ? @"uc_coupon_colorBg2_sel" : @"uc_coupon_colorBg2"]; self.ln1.image = [UIImage imageNamed:isUsed ? @"uc_coupon_line1_sel" : @"uc_coupon_line1"]; self.ln2.image = [UIImage imageNamed:isUsed ? @"uc_coupon_line2_sel" : @"uc_coupon_line2"]; self.sep.image = [UIImage imageNamed:isUsed ? @"uc_coupon_sep_sel" : @"uc_coupon_sep"]; } - (void)loadSubVs { self.backgroundColor = UIColor.clearColor; self.contentView.backgroundColor = UIColor.clearColor; self.selectionStyle = UITableViewCellSelectionStyleNone; [self.contentView addSubview:self.bgV]; [self.bgV addSubview:self.bg1]; [self.bgV addSubview:self.bg2]; [self.bgV addSubview:self.ln1]; [self.bgV addSubview:self.ln2]; [self.bgV addSubview:self.sep]; //229/106 [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@100); make.leading.equalTo(self.contentView).offset(20); make.trailing.equalTo(self.contentView).offset(-20); make.top.equalTo(self.contentView).offset(15); make.bottom.equalTo(self.contentView).offset(-5); }]; [self.bg1 mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.bgV); }]; [self.bg2 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.trailing.equalTo(self.bgV); make.width.equalTo(self.bgV).multipliedBy(106.0/(229+106)); }]; [self.sep mas_makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(@3); make.top.bottom.equalTo(self.bgV); make.centerX.equalTo(self.bg2.mas_leading); }]; [self.ln1 mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.bgV); }]; [self.ln2 mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.bgV).offset(5); make.trailing.equalTo(self.bgV).offset(-5); make.top.equalTo(self.bgV).offset(5); make.bottom.equalTo(self.bgV).offset(-5); }]; [self.bgV addSubview:self.titleLb]; [self.bgV addSubview:self.ruleLb]; [self.bgV addSubview:self.dateLb]; UIStackView *st = [UIStackView baseStackV:true]; st.spacing = 0; st.distribution = UIStackViewDistributionFill; [self.bgV addSubview:st]; [st addArrangedSubview:self.cpLb]; [st addArrangedSubview:self.codeTitleLb]; [st addArrangedSubview:self.codeLb]; [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.bgV).offset(16); make.leading.equalTo(self.bgV).offset(30); make.trailing.equalTo(self.sep.mas_leading).offset(-8); make.height.equalTo(@34); }]; [self.ruleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.titleLb.mas_bottom); make.leading.trailing.equalTo(self.titleLb); make.height.equalTo(@14); }]; [self.dateLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.ruleLb.mas_bottom).offset(6); make.leading.trailing.equalTo(self.titleLb); make.height.equalTo(@14); }]; [st mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.bg2); make.centerX.equalTo(self.bg2).offset(-8); make.width.equalTo(@80); }]; [self.cpLb mas_makeConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@34); }]; [self.codeTitleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@17); }]; [self.codeLb mas_makeConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@17); }]; [self.bgV addSubview:self.cpBt]; [self.cpBt mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.bg2); }]; st.transform = CGAffineTransformRotate(st.transform, -M_PI/2.0); [self.bgV addSubview:self.usedLb]; [self.usedLb mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(self.bgV); }]; self.usedLb.transform = CGAffineTransformRotate(self.usedLb.transform, -M_PI/6.0); } - (UIView *)bgV { if (!_bgV) { UIView *v = [UIView baseV]; v.backgroundColor = UIColor.clearColor; v.clipsToBounds = true; _bgV = v; } return _bgV; } - (UIImageView *)bg1 { if (!_bg1) { UIImageView *v = [UIImageView baseImgV]; v.contentMode = UIViewContentModeScaleToFill; v.clipsToBounds = true; v.image = [UIImage imageNamed:@"uc_coupon_colorBg1"]; _bg1 = v; } return _bg1; } - (UIImageView *)bg2 { if (!_bg2) { UIImageView *v = [UIImageView baseImgV]; v.contentMode = UIViewContentModeScaleToFill; v.userInteractionEnabled = true; v.clipsToBounds = true; v.image = [UIImage imageNamed:@"uc_coupon_colorBg2"]; _bg2 = v; } return _bg2; } - (UIImageView *)ln1 { if (!_ln1) { UIImageView *v = [UIImageView baseImgV]; v.contentMode = UIViewContentModeScaleToFill; v.clipsToBounds = true; v.image = [UIImage imageNamed:@"uc_coupon_line1"]; _ln1 = v; } return _ln1; } - (UIImageView *)ln2 { if (!_ln2) { UIImageView *v = [UIImageView baseImgV]; v.contentMode = UIViewContentModeScaleToFill; v.clipsToBounds = true; v.image = [UIImage imageNamed:@"uc_coupon_line2"]; _ln2 = v; } return _ln2; } - (UIImageView *)sep { if (!_sep) { UIImageView *v = [UIImageView baseImgV]; v.contentMode = UIViewContentModeScaleAspectFill; v.clipsToBounds = true; v.image = [UIImage imageNamed:@"uc_coupon_sep"]; _sep = v; } return _sep; } - (UILabel *)titleLb { if (!_titleLb) { UILabel *lb = [UILabel baseLb]; lb.font = [UIFont fontWithName:Rob_BlackItalic size:28]; lb.textColor = Col_000; _titleLb = lb; } return _titleLb; } - (UILabel *)ruleLb { if (!_ruleLb) { UILabel *lb = [UILabel baseLb]; lb.font = [UIFont fontWithName:Rob_Regular size:12]; lb.textColor = _043632; _ruleLb = lb; } return _ruleLb; } - (UILabel *)dateLb { if (!_dateLb) { UILabel *lb = [UILabel baseLb]; lb.font = [UIFont fontWithName:Rob_Regular size:12]; lb.textColor = _128273; _dateLb = lb; } return _dateLb; } - (UILabel *)cpLb { if (!_cpLb) { UILabel *lb = [UILabel baseLb]; lb.font = [UIFont fontWithName:Rob_Black size:28]; lb.textColor = Col_FFF; lb.text = @"COPY"; lb.textAlignment = NSTextAlignmentCenter; _cpLb = lb; } return _cpLb; } - (UILabel *)codeTitleLb { if (!_codeTitleLb) { UILabel *lb = [UILabel baseLb]; lb.font = [UIFont fontWithName:Rob_Regular size:14]; lb.textAlignment = NSTextAlignmentCenter; lb.textColor = _043632; lb.text = @"CODE"; _codeTitleLb = lb; } return _codeTitleLb; } - (UILabel *)codeLb { if (!_codeLb) { UILabel *lb = [UILabel baseLb]; lb.textAlignment = NSTextAlignmentCenter; lb.font = [UIFont fontWithName:Rob_Regular size:14]; lb.textColor = _043632; _codeLb = lb; } return _codeLb; } - (UILabel *)usedLb { if (!_usedLb) { UILabel *lb = [UILabel baseLb]; lb.textAlignment = NSTextAlignmentCenter; lb.font = [UIFont fontWithName:Rob_Bold size:48]; lb.textColor = Col_666; lb.text = @"USED"; lb.hidden = true; _usedLb = lb; } return _usedLb; } - (UIButton *)cpBt { if (!_cpBt) { UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom]; [bt addTarget: self action:@selector(copyAction) forControlEvents:UIControlEventTouchUpInside]; _cpBt = bt; } return _cpBt; } - (void)copyAction { if (!self.codeLb.text.isEmpty) { UIPasteboard.generalPasteboard.string = self.codeLb.text; } if (self.copyCallBack){ self.copyCallBack(); } } @end