// // YMIAPRechargeCollectionViewCell.m // YUMI // // Created by XY on 2023/2/21. // #import "XPIAPRechargeCollectionViewCell.h" #import "DJDKMIMOMColor.h" #import #import "RechargeListModel.h" #import "FirstRechargeManager.h" #import "MoliMoneyLabel.h" @interface XPIAPRechargeCollectionViewCell() /// 背景 @property (nonatomic, strong) UIView *bgView; @property(nonatomic,strong) UIView *bgPriceView; /// 价格 @property (nonatomic, strong) UILabel *priceLabel; /// 💎 @property (nonatomic, strong) UIImageView *iconImageView; /// 数量 @property (nonatomic, strong) UILabel *numLabel; @property (nonatomic, strong) UIView *extBG; @property (nonatomic, strong) MoliMoneyLabel *moneyLabel; @end @implementation XPIAPRechargeCollectionViewCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self createUI]; } return self; } - (void)createUI { [self.contentView addSubview:self.bgView]; [self.bgView addSubview:self.bgPriceView]; [self.bgPriceView addSubview:self.priceLabel]; [self.bgView addSubview:self.iconImageView]; [self.bgView addSubview:self.numLabel]; [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.contentView); }]; [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(kGetScaleWidth(13)); make.width.mas_equalTo(kGetScaleWidth(55)); make.height.mas_equalTo(kGetScaleWidth(48)); make.centerX.equalTo(self.bgView); }]; [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.equalTo(self.bgView).inset(kGetScaleWidth(0)); make.top.mas_equalTo(kGetScaleWidth(66)); }]; [self.bgPriceView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.bottom.equalTo(self.bgView); make.height.mas_equalTo(kGetScaleWidth(26)); }]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.bgPriceView); }]; [self.contentView addSubview:self.extBG]; [self.extBG mas_makeConstraints:^(MASConstraintMaker *make) { make.top.trailing.mas_equalTo(self.bgView); make.size.mas_equalTo(CGSizeMake(64, 20)); }]; [self.contentView addSubview:self.moneyLabel]; [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.extBG); make.trailing.mas_equalTo(self.extBG).offset(-5); }]; } - (void)setRechargeModel:(RechargeListModel *)rechargeModel { _rechargeModel = rechargeModel; NSMutableAttributedString *priceStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"$%.2f",rechargeModel.money.floatValue]]; self.priceLabel.attributedText = priceStr; self.numLabel.text = [NSString stringWithFormat:@"%ld", (long)rechargeModel.chargeGoldNum]; self.extBG.hidden = YES; self.moneyLabel.hidden = YES; FirstRechargeModel *model = [FirstRechargeManager.sharedManager loadCurrentModel]; if (model && model.chargeStatus == NO) { for (FirstRechargeLevelModel *levelModel in model.levelCharge) { if (levelModel.exp == rechargeModel.chargeGoldNum) { [self.moneyLabel updateContent: [NSString stringWithFormat:@"+ %@", @(levelModel.awardNum)]]; self.extBG.hidden = NO; self.moneyLabel.hidden = NO; break; } } } } - (void)setSelectedStyle:(BOOL)selectedStyle { _selectedStyle = selectedStyle; _bgView.layer.borderWidth = _selectedStyle ? 1 : 0; } #pragma mark - 懒加载 - (UIView *)bgView { if (!_bgView) { _bgView = [[UIView alloc] init]; _bgView.backgroundColor = UIColorFromRGB(0xF3F0E6); _bgView.layer.cornerRadius = kGetScaleWidth(9); _bgView.layer.masksToBounds = YES; _bgView.layer.borderColor = UIColorFromRGB(0xFFB05E).CGColor; } return _bgView; } - (UIView *)bgPriceView{ if(!_bgPriceView){ _bgPriceView = [UIView new]; _bgPriceView.backgroundColor = UIColorFromRGB(0xFFF09C); } return _bgPriceView; } - (UILabel *)priceLabel { if (!_priceLabel) { _priceLabel = [[UILabel alloc] init]; _priceLabel.textColor = UIColorFromRGB(0x513C0B); _priceLabel.font = kFontBold(12); _priceLabel.textAlignment = NSTextAlignmentCenter; } return _priceLabel; } - (UIImageView *)iconImageView { if (!_iconImageView) { _iconImageView = [[UIImageView alloc] init]; _iconImageView.contentMode = UIViewContentModeScaleAspectFit; _iconImageView.image = [UIImage imageNamed:@"ms_mine_recharge_coin"]; } return _iconImageView; } - (UILabel *)numLabel { if (!_numLabel) { _numLabel = [[UILabel alloc] init]; _numLabel.textColor = UIColorFromRGB(0x8A4B00); _numLabel.font = kFontBold(15); _numLabel.textAlignment = NSTextAlignmentCenter; } return _numLabel; } - (UIView *)extBG { if (!_extBG) { _extBG = [[UIView alloc] init]; [_extBG addGradientBackgroundWithColors:@[ UIColorFromRGB(0xFFE347), UIColorFromRGB(0xFF9A51), ] startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 0.5) cornerRadius:4]; [_extBG setCornerWithLeftTopCorner:4 rightTopCorner:kGetScaleWidth(9) bottomLeftCorner:4 bottomRightCorner:4 size:CGSizeMake(64, 20)]; } return _extBG; } - (MoliMoneyLabel *)moneyLabel { if (!_moneyLabel) { _moneyLabel = [MoliMoneyLabel moneyLabelWithTextColot:UIColorFromRGB(0x582B00) font:kFontMedium(13) moneyPostion:2 moneySize:CGSizeMake(14, 14)]; } return _moneyLabel; } @end