Files
peko-ios/YuMi/Modules/YMMine/View/Recharge/XPIAPRechargeCollectionViewCell.m

137 lines
4.4 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
// 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.contentView addSubview:self.selectedBgView];
[self.contentView addSubview:self.priceLabel];
[self.contentView addSubview:self.iconImageView];
[self.contentView addSubview:self.numLabel];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
[self.selectedBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.bgView);
}];
[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(10);
make.left.mas_equalTo(4);
make.right.mas_equalTo(-4);
}];
[self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView).offset(8);
make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(5);
make.left.mas_greaterThanOrEqualTo(18);
}];
[self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.numLabel);
make.width.height.mas_equalTo(14);
make.right.mas_equalTo(self.numLabel.mas_left).offset(-4);
}];
}
- (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 = UIColor.whiteColor;
_bgView.layer.cornerRadius = 5;
}
return _bgView;
}
- (UIView *)selectedBgView {
if (!_selectedBgView) {
_selectedBgView = [[UIView alloc] init];
_selectedBgView.backgroundColor = [[DJDKMIMOMColor appMainColor] colorWithAlphaComponent:0.1];
_selectedBgView.layer.cornerRadius = 5;
_selectedBgView.layer.borderWidth = 1;
_selectedBgView.layer.borderColor = [DJDKMIMOMColor appMainColor].CGColor;
_selectedBgView.hidden = YES;
}
return _selectedBgView;
}
- (UILabel *)priceLabel {
if (!_priceLabel) {
_priceLabel = [[UILabel alloc] init];
_priceLabel.textColor = [DJDKMIMOMColor mainTextColor];
_priceLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
_priceLabel.textAlignment = NSTextAlignmentCenter;
}
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 = [DJDKMIMOMColor textThirdColor];
_numLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightRegular];
_numLabel.textAlignment = NSTextAlignmentCenter;
}
return _numLabel;
}
@end