Files
yinmeng-ios/xplan-ios/Main/Mine/View/Cell/Recharge/XPMineRechargeCollectionViewCell.m
2023-03-17 21:46:02 +08:00

141 lines
4.4 KiB
Objective-C

//
// XPMineRechargeCollectionViewCell.m
// xplan-ios
//
// Created by XY on 2023/2/21.
//
#import "XPMineRechargeCollectionViewCell.h"
#import "ThemeColor.h"
#import <Masonry.h>
#import "RechargeListModel.h"
@interface XPMineRechargeCollectionViewCell()
/// 背景
@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 XPMineRechargeCollectionViewCell
- (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.centerY.mas_equalTo(12);
make.left.mas_equalTo(4);
make.right.mas_equalTo(-4);
}];
[self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView).offset(12);
make.bottom.mas_equalTo(self.priceLabel.mas_top).offset(-5);
make.left.mas_greaterThanOrEqualTo(18);
}];
[self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.numLabel);
make.width.height.mas_equalTo(20);
make.right.mas_equalTo(self.numLabel.mas_left).offset(-4);
}];
}
- (void)setRechargeModel:(RechargeListModel *)rechargeModel {
_rechargeModel = rechargeModel;
self.priceLabel.text = [NSString stringWithFormat:@"%@元",rechargeModel.money.stringValue];
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;
if (selectedStyle) {
self.selectedBgView.hidden = NO;
self.bgView.backgroundColor = UIColor.clearColor;
}else{
self.selectedBgView.hidden = YES;
self.bgView.backgroundColor = [ThemeColor colorWithHexString:@"#F8F8FA"];
}
}
#pragma mark - Getters And Setters
- (UIView *)bgView {
if (!_bgView) {
_bgView = [[UIView alloc] init];
_bgView.backgroundColor = [ThemeColor colorWithHexString:@"#F8F8FA"];
_bgView.layer.cornerRadius = 5;
}
return _bgView;
}
- (UIView *)selectedBgView {
if (!_selectedBgView) {
_selectedBgView = [[UIView alloc] init];
_selectedBgView.backgroundColor = [[ThemeColor appMainColor] colorWithAlphaComponent:0.15];
_selectedBgView.layer.cornerRadius = 5;
_selectedBgView.layer.borderWidth = 1;
_selectedBgView.layer.borderColor = [ThemeColor appMainColor].CGColor;
_selectedBgView.hidden = YES;
}
return _selectedBgView;
}
- (UILabel *)priceLabel {
if (!_priceLabel) {
_priceLabel = [[UILabel alloc] init];
_priceLabel.textColor = [ThemeColor textThirdColor];
_priceLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
_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 = [ThemeColor mainTextColor];
_numLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
_numLabel.textAlignment = NSTextAlignmentCenter;
}
return _numLabel;
}
@end