147 lines
4.7 KiB
Objective-C
147 lines
4.7 KiB
Objective-C
//
|
|
// XPMineRechargeTableViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/9/24.
|
|
//
|
|
|
|
#import "XPMineRechargeTableViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor.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.left.right.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.left.mas_equalTo(self.backView).offset(19);
|
|
}];
|
|
|
|
[self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.coinImageView);
|
|
make.left.mas_equalTo(self.coinImageView.mas_right).offset(6);
|
|
}];
|
|
|
|
[self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self.numberLabel);
|
|
make.left.mas_equalTo(self.numberLabel.mas_right).offset(6);
|
|
}];
|
|
|
|
[self.rechargeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(54, 24));
|
|
make.centerY.mas_equalTo(self.backView);
|
|
make.right.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 = [ThemeColor 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:@""];
|
|
}
|
|
return _coinImageView;
|
|
}
|
|
|
|
- (UILabel *)numberLabel {
|
|
if (!_numberLabel) {
|
|
_numberLabel = [[UILabel alloc] init];
|
|
_numberLabel.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:18];
|
|
_numberLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _numberLabel;
|
|
}
|
|
|
|
- (UILabel *)unitLabel {
|
|
if (!_unitLabel) {
|
|
_unitLabel = [[UILabel alloc] init];
|
|
_unitLabel.text = @"钻石";
|
|
_unitLabel.font = [UIFont systemFontOfSize:11];
|
|
_unitLabel.textColor = [ThemeColor secondTextColor];
|
|
}
|
|
return _unitLabel;
|
|
}
|
|
|
|
- (UIButton *)rechargeButton {
|
|
if (!_rechargeButton) {
|
|
_rechargeButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_rechargeButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateNormal];
|
|
_rechargeButton.titleLabel.font = [UIFont systemFontOfSize:15];
|
|
_rechargeButton.layer.masksToBounds = YES;
|
|
_rechargeButton.layer.cornerRadius = 12;
|
|
_rechargeButton.layer.borderWidth = 1;
|
|
_rechargeButton.layer.borderColor = [ThemeColor mainTextColor].CGColor;
|
|
[_rechargeButton addTarget:self action:@selector(rechargeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _rechargeButton;
|
|
}
|
|
|
|
@end
|