| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 | ////  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
 |