// // ASGiftCardAvailabelCell.m // Asteria // // Created by iOS on 2023/11/2. // #import "ASGiftCardAvailabelCell.h" @interface ASGiftCardAvailabelCell () @property (nonatomic, assign) ASGiftCardState state; @property (nonatomic, strong) UIView *cardBgV; @property (nonatomic, strong) UIImageView *bgImgV; @property (nonatomic, strong) UIButton *cardIcon; @property (nonatomic, strong) UILabel *priceLb; @property (nonatomic, strong) UILabel *desLb; @property (nonatomic, strong) UILabel *timeLb; @property (nonatomic, strong) UIImageView *tagImgV; @end @implementation ASGiftCardAvailabelCell - (void)setState:(ASGiftCardState)state { switch (state) { case ASGiftCardStateUsed: _priceLb.textColor = _DBDBDB; _cardIcon.selected = true; _timeLb.hidden = true; _desLb.textColor = _DBDBDB; _bgImgV.hidden = true; _tagImgV.hidden = false; _tagImgV.image = [UIImage imageNamed:@"mine_giftcard_usedTag"]; break; case ASGiftCardStateExpired: _priceLb.textColor = _DBDBDB; _cardIcon.selected = true; _timeLb.hidden = true; _desLb.textColor = _DBDBDB; _bgImgV.hidden = true; _tagImgV.hidden = false; _tagImgV.image = [UIImage imageNamed:@"mine_giftcard_expiredTag"]; break; default: _priceLb.textColor = Col_FFF; _timeLb.hidden = false; _desLb.textColor = Col_FFF; _cardIcon.selected = false; _bgImgV.hidden = false; _tagImgV.hidden = true; break; } } - (void)setData:(ASGiftCardModel *)m { self.priceLb.text = m.giftcard_amount; self.desLb.text = @"For All Product"; self.timeLb.text = [NSString stringWithFormat:@"Expires in: %@", m.timeStr]; self.state = m.state; } - (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 loadSubV]; } return self; } - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self loadSubV]; } return self; } - (void)loadSubV { self.selectionStyle = UITableViewCellSelectionStyleNone; self.contentView.backgroundColor = UIColor.clearColor; self.backgroundColor = UIColor.clearColor; [self.contentView addSubview:self.cardBgV]; [self.cardBgV addSubview:self.bgImgV]; [self.cardBgV addSubview:self.tagImgV]; [self.cardBgV addSubview:self.cardIcon]; [self.cardBgV addSubview:self.priceLb]; [self.cardBgV addSubview:self.desLb]; [self.cardBgV addSubview:self.timeLb]; self.tagImgV.hidden = true; [self.cardBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(10); make.bottom.equalTo(self.contentView).offset(-10); make.leading.equalTo(self.contentView).offset(20); make.trailing.equalTo(self.contentView).offset(-20); }]; [self.bgImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.cardBgV); make.height.equalTo(self.bgImgV.mas_width).multipliedBy(2/3.35); }]; [self.tagImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.cardBgV); make.height.equalTo(self.bgImgV.mas_width).multipliedBy(2/3.35); }]; [self.cardIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.cardBgV).offset(15); make.top.equalTo(self.cardBgV).offset(15); make.height.equalTo(@30); make.width.equalTo(@98); }]; [self.priceLb mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.cardBgV).offset(20); make.height.equalTo(@38); make.trailing.lessThanOrEqualTo(self.cardBgV).offset(-20); }]; [self.desLb mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.priceLb); make.bottom.equalTo(self.cardBgV).offset(-20); make.height.equalTo(@14); make.top.equalTo(self.priceLb.mas_bottom).offset(5); }]; [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) { make.trailing.equalTo(self.cardBgV).offset(-20); make.bottom.equalTo(self.desLb); make.height.equalTo(@17); make.leading.equalTo(self.desLb.mas_trailing).offset(10); }]; [self.timeLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; } - (UIView *)cardBgV { if (!_cardBgV) { UIView *v = [UIView baseV]; v.layer.cornerRadius = 8; v.layer.masksToBounds = true; v.backgroundColor = UIColor.whiteColor; _cardBgV = v; } return _cardBgV; } - (UIImageView *)bgImgV { if (!_bgImgV) { UIImageView *v = [UIImageView baseImgV]; v.contentMode = UIViewContentModeScaleAspectFill; v.clipsToBounds = true; v.image = [UIImage imageNamed:@"mine_giftcard_bg"]; _bgImgV = v; } return _bgImgV; } - (UIImageView *)tagImgV { if (!_tagImgV) { UIImageView *v = [UIImageView baseImgV]; v.contentMode = UIViewContentModeScaleAspectFill; v.clipsToBounds = true; v.backgroundColor = _E8E8E8; v.image = [UIImage imageNamed:@"mine_giftcard_bg"]; _tagImgV = v; } return _tagImgV; } - (UIButton *)cardIcon { if (!_cardIcon) { UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom]; [bt setTitle:@"GIFT CARD" forState:UIControlStateNormal]; bt.titleLabel.font = [UIFont fontWithName:Rob_Bold size:12]; [bt setImage:[UIImage imageNamed:@"mine_giftcard_icon"] forState:UIControlStateNormal]; [bt setTitleColor:Col_FFF forState:UIControlStateNormal]; [bt setImage:[UIImage imageNamed:@"mine_giftcard_icon_disabel"] forState:UIControlStateSelected]; [bt setTitleColor:_DBDBDB forState:UIControlStateSelected]; bt.imageEdgeInsets = UIEdgeInsetsMake(0, -4, 0, 4); _cardIcon = bt; } return _cardIcon; } - (UILabel *)priceLb { if (!_priceLb) { UILabel *lb = [UILabel baseLb]; lb.font = [UIFont fontWithName:Rob_BlackItalic size:32]; lb.textColor = Col_FFF; _priceLb = lb; } return _priceLb; } - (UILabel *)desLb { if (!_desLb) { UILabel *lb = [UILabel baseLb]; lb.font = [UIFont fontWithName:Rob_Regular size:12]; lb.textColor = Col_FFF; _desLb = lb; } return _desLb; } - (UILabel *)timeLb { if (!_timeLb) { UILabel *lb = [UILabel baseLb]; lb.font = [UIFont fontWithName:Rob_Bold size:14]; lb.textAlignment = NSTextAlignmentRight; lb.textColor = Col_FFF; _timeLb = lb; } return _timeLb; } @end