Files
peko-ios/YuMi/Modules/YMMine/View/Recharge/XPIAPRechargeCollectionViewCell.m
2024-06-04 18:10:44 +08:00

138 lines
4.1 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 *bgPriceView;
/// 价格
@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.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);
}];
}
- (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;
_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;
}
@end