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

147 lines
4.8 KiB
Objective-C

//
// YMMineRechargeTableViewCell.m
// YUMI
//
// Created by YUMI on 2021/9/24.
//
#import "XPMineRechargeTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "DJDKMIMOMColor.h"
///Model
#import "RechargeListModel.h"
@interface XPMineRechargeTableViewCell ()
///背景
@property (nonatomic,strong) UIView * backView;
///💎的标志
@property (nonatomic,strong) UIImageView *coinImageView;
///数量
@property (nonatomic,strong) UILabel *numberLabel;
///单位
@property (nonatomic,strong) UILabel *unitLabel;
///充值
@property (nonatomic,strong) UIButton *rechargeButton;
@end
@implementation XPMineRechargeTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Response
- (void)rechargeButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineRechargeTableViewCell:didSelectItem:)]) {
[self.delegate xPMineRechargeTableViewCell:self didSelectItem:self.listModel];
}
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.coinImageView];
[self.backView addSubview:self.numberLabel];
[self.backView addSubview:self.unitLabel];
[self.backView addSubview:self.rechargeButton];
}
- (void)initSubViewConstraints {
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.contentView).inset(15);
make.top.mas_equalTo(self.contentView).offset(15);
make.bottom.mas_equalTo(self.contentView);
}];
[self.coinImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(21, 21));
make.centerY.mas_equalTo(self.backView);
make.leading.mas_equalTo(self.backView).offset(19);
}];
[self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.coinImageView);
make.leading.mas_equalTo(self.coinImageView.mas_trailing).offset(6);
}];
[self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.numberLabel);
make.leading.mas_equalTo(self.numberLabel.mas_trailing).offset(6);
}];
[self.rechargeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(54, 24));
make.centerY.mas_equalTo(self.backView);
make.trailing.mas_equalTo(self.backView).offset(-15);
}];
}
#pragma mark - Getters And Setters
- (void)setListModel:(RechargeListModel *)listModel {
_listModel = listModel;
if (_listModel) {
NSCharacterSet* nonDigits =[[NSCharacterSet decimalDigitCharacterSet] invertedSet];
int remainSecond = [[_listModel.prodName stringByTrimmingCharactersInSet:nonDigits] intValue];
self.numberLabel.text = [NSString stringWithFormat:@"%d",remainSecond];
[self.rechargeButton setTitle:[NSString stringWithFormat:@"¥%@",[_listModel.money stringValue]] forState:UIControlStateNormal];
}
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = [DJDKMIMOMColor appCellBackgroundColor];
_backView.layer.masksToBounds = YES;
_backView.layer.cornerRadius = 8;
}
return _backView;
}
- (UIImageView *)coinImageView {
if (!_coinImageView) {
_coinImageView = [[UIImageView alloc] init];
_coinImageView.userInteractionEnabled = YES;
_coinImageView.image = [UIImage imageNamed:@"moli_money_icon"];
}
return _coinImageView;
}
- (UILabel *)numberLabel {
if (!_numberLabel) {
_numberLabel = [[UILabel alloc] init];
_numberLabel.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:18];
_numberLabel.textColor = [DJDKMIMOMColor mainTextColor];
}
return _numberLabel;
}
- (UILabel *)unitLabel {
if (!_unitLabel) {
_unitLabel = [[UILabel alloc] init];
_unitLabel.text = YMLocalizedString(@"XPMineRechargeTableViewCell0");
_unitLabel.font = [UIFont systemFontOfSize:11];
_unitLabel.textColor = [DJDKMIMOMColor secondTextColor];
}
return _unitLabel;
}
- (UIButton *)rechargeButton {
if (!_rechargeButton) {
_rechargeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_rechargeButton setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateNormal];
_rechargeButton.titleLabel.font = [UIFont systemFontOfSize:15];
_rechargeButton.layer.masksToBounds = YES;
_rechargeButton.layer.cornerRadius = 12;
_rechargeButton.layer.borderWidth = 1;
_rechargeButton.layer.borderColor = [DJDKMIMOMColor mainTextColor].CGColor;
[_rechargeButton addTarget:self action:@selector(rechargeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _rechargeButton;
}
@end