Files
peko-ios/YuMi/Modules/YMMine/View/Recharge/XPIAPRechargeCollectionViewCell.m
2023-09-12 18:12:11 +08:00

143 lines
4.9 KiB
Objective-C

//
// YMIAPRechargeCollectionViewCell.m
// YUMI
//
// Created by XY on 2023/2/21.
//
#import "XPIAPRechargeCollectionViewCell.h"
#import "DJDKMIMOMColor.h"
#import <Masonry.h>
#import "RechargeListModel.h"
@interface XPIAPRechargeCollectionViewCell()
/// 背景
@property (nonatomic, strong) UIView *bgView;
/// 选中背景
@property (nonatomic, strong) UIView *selectedBgView;
/// 价格
@property (nonatomic, strong) UILabel *priceLabel;
/// 💎
@property (nonatomic, strong) UIImageView *iconImageView;
/// 数量
@property (nonatomic, strong) UILabel *numLabel;
@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.selectedBgView];
[self.bgView addSubview:self.priceLabel];
[self.bgView addSubview:self.iconImageView];
[self.bgView addSubview:self.numLabel];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.equalTo(self.contentView).inset(kGetScaleWidth(16));
make.top.mas_equalTo(kGetScaleWidth(0));
make.height.mas_equalTo(kGetScaleWidth(60));
}];
[self.selectedBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.bgView);
}];
[self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.bgView);
make.width.height.mas_equalTo(kGetScaleWidth(24));
make.leading.mas_equalTo(kGetScaleWidth(18));
}];
[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-kGetScaleWidth(18));
make.centerY.equalTo(self.bgView);
}];
[self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.bgView);
make.leading.equalTo(self.iconImageView.mas_trailing).mas_offset(kGetScaleWidth(5));
}];
}
- (void)setRechargeModel:(RechargeListModel *)rechargeModel {
_rechargeModel = rechargeModel;
NSMutableAttributedString *priceStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"$%.2f",rechargeModel.money.floatValue]];
// [priceStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:8] range:NSMakeRange(0, 1)];
self.priceLabel.attributedText = priceStr;
NSCharacterSet* nonDigits =[[NSCharacterSet decimalDigitCharacterSet] invertedSet];
int remainSecond = [[rechargeModel.prodName stringByTrimmingCharactersInSet:nonDigits] intValue];
self.numLabel.text = [NSString stringWithFormat:@"%d",remainSecond];
}
- (void)setSelectedStyle:(BOOL)selectedStyle {
_selectedStyle = selectedStyle;
self.selectedBgView.hidden = !selectedStyle;
}
#pragma mark - 懒加载
- (UIView *)bgView {
if (!_bgView) {
_bgView = [[UIView alloc] init];
_bgView.backgroundColor = UIColorFromRGB(0xF0F5F6);
_bgView.layer.cornerRadius = kGetScaleWidth(13);
_bgView.layer.masksToBounds = YES;
}
return _bgView;
}
- (UIView *)selectedBgView {
if (!_selectedBgView) {
_selectedBgView = [[UIView alloc] init];
UIImage *bgImage = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xE6FDFF),UIColorFromRGB(0xFAEDFF)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(343), kGetScaleWidth(60))];
UIImage *image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0x13E2F5),UIColorFromRGB(0x9DB4FF),UIColorFromRGB(0xCC67FF)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(344), kGetScaleWidth(60))];
_selectedBgView.backgroundColor = [UIColor colorWithPatternImage:bgImage];
_selectedBgView.layer.cornerRadius = kGetScaleWidth(13);
_selectedBgView.layer.masksToBounds = YES;
_selectedBgView.layer.borderColor = [UIColor colorWithPatternImage:image].CGColor;
_selectedBgView.layer.borderWidth = 1;
_selectedBgView.hidden = YES;
}
return _selectedBgView;
}
- (UILabel *)priceLabel {
if (!_priceLabel) {
_priceLabel = [[UILabel alloc] init];
_priceLabel.textColor = UIColorFromRGB(0x1F1B4F);
_priceLabel.font = kFontMedium(18);
}
return _priceLabel;
}
- (UIImageView *)iconImageView {
if (!_iconImageView) {
_iconImageView = [[UIImageView alloc] init];
_iconImageView.contentMode = UIViewContentModeScaleAspectFit;
_iconImageView.image = [UIImage imageNamed:@"mine_recharge_diamond"];
}
return _iconImageView;
}
- (UILabel *)numLabel {
if (!_numLabel) {
_numLabel = [[UILabel alloc] init];
_numLabel.textColor = UIColorFromRGB(0x1F1B4F);
_numLabel.font = kFontBold(20);
_numLabel.textAlignment = NSTextAlignmentCenter;
}
return _numLabel;
}
@end