Files
peko-ios/YuMi/Modules/YMMine/View/Noble/View/SubViews/XPNobleCenterPayView.m
liyuhua 2bcccf8fde 优化
2023-09-28 14:08:01 +08:00

195 lines
7.7 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// XPNobleCenterPayView.m
// YuMi
//
// Created by duoban on 2023/7/12.
//
#import "XPNobleCenterPayView.h"
#import "XPNobleCenterPayCell.h"
@interface XPNobleCenterPayView()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UIView *bgView;
@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong) UILabel *titleView;
@property(nonatomic,strong) UILabel *diamondNumView;
@property(nonatomic,strong) UILabel *diamondNumTitle;
@property(nonatomic,strong) UIButton *payBtn;
@property(nonatomic,copy) NSArray *listData;
@property(nonatomic,strong) NSIndexPath *path;
@property(nonatomic,strong) UIButton *backBtn;
@property(nonatomic,assign) NobleCenterPayType type;
@end
@implementation XPNobleCenterPayView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
self.path = [NSIndexPath indexPathForRow:0 inSection:0];
self.type = NobleCenterPayType_diamond;
self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
[self addSubview:self.backBtn];
[self addSubview:self.bgView];
[self.bgView addSubview:self.titleView];
[self.bgView addSubview:self.diamondNumView];
[self.bgView addSubview:self.diamondNumTitle];
[self.bgView addSubview:self.tableView];
[self.bgView addSubview:self.payBtn];
}
-(void)installConstraints{
[self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.leading.bottom.equalTo(self);
make.height.mas_equalTo(319);
}];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(24);
make.centerX.equalTo(self.bgView);
}];
[self.diamondNumView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(76);
make.centerX.equalTo(self.bgView);
}];
[self.diamondNumTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(108);
make.centerX.equalTo(self.bgView);
}];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(138);
make.leading.trailing.equalTo(self);
make.bottom.mas_equalTo(-124);
}];
[self.payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(-58);
make.width.mas_equalTo(303);
make.height.mas_equalTo(48);
make.centerX.equalTo(self.bgView);
}];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.listData.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
XPNobleCenterPayCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNobleCenterPayCell class]) forIndexPath:indexPath];
cell.isChoose = indexPath.row == self.path.row;
cell.iconImage = indexPath.row == 0 ? kImage( @"mine_noble_center__diamond") : kImage(@"mine_noble_center_apple");
NSString *num = [NSString stringWithFormat:@"%@%@",self.diamonds,YMLocalizedString(@"XPNobleCenterPayView1")];
NSString *text = indexPath.row == 0 ? [NSString stringWithFormat:@"%@%@",self.listData[indexPath.row],num] : self.listData[indexPath.row];
NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc]initWithString:text attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16 weight:UIFontWeightSemibold],NSForegroundColorAttributeName:UIColorFromRGB(0x1F1B4F)}];
if(indexPath.row == 0){
[titleAtt addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular],NSForegroundColorAttributeName:UIColorFromRGB(0x8A8CAB)} range:[text rangeOfString:num]];
}
cell.titleAtt = titleAtt;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.path = indexPath;
self.type = indexPath.row == 0 ? NobleCenterPayType_diamond : NobleCenterPayType_Apple;
self.diamondNumView.text = indexPath.row == 0 ? @"2990" : @"$2.99";
self.diamondNumTitle.text = indexPath.row == 0 ? YMLocalizedString(@"XPNobleCenterPayView1"):@"";
[self.tableView reloadData];
}
-(void)backAction{
[self removeFromSuperview];
}
-(void)setDiamonds:(NSString *)diamonds{
_diamonds = diamonds;
[self.tableView reloadData];
}
-(void)payBtnAction{
[self backAction];
if(self.delegate && [self.delegate respondsToSelector:@selector(payWithType:)]){
[self.delegate payWithType:self.type];
}
}
#pragma mark - 懒加载
- (UIView *)bgView{
if(!_bgView){
_bgView = [UIView new];
_bgView.backgroundColor = [UIColor whiteColor];
[_bgView setCornerWithLeftTopCorner:28 rightTopCorner:28 bottomLeftCorner:0 bottomRightCorner:0 size:CGSizeMake(KScreenWidth, 487)];
}
return _bgView;
}
- (UILabel *)titleView{
if(!_titleView){
_titleView = [UILabel new];
_titleView.text = YMLocalizedString(@"XPNobleCenterPayView0");
_titleView.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
_titleView.textColor = UIColorFromRGB(0x1F1B4F);
}
return _titleView;
}
- (UILabel *)diamondNumView{
if(!_diamondNumView){
_diamondNumView = [UILabel new];
_diamondNumView.text = @"2990";
_diamondNumView.font = [UIFont systemFontOfSize:28 weight:UIFontWeightSemibold];
_diamondNumView.textColor = UIColorFromRGB(0x9168FA);
}
return _diamondNumView;
}
- (UILabel *)diamondNumTitle{
if(!_diamondNumTitle){
_diamondNumTitle = [UILabel new];
_diamondNumTitle.text = YMLocalizedString(@"XPNobleCenterPayView1");;
_diamondNumTitle.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
_diamondNumTitle.textColor = UIColorFromRGB(0x8A8CAB);
}
return _diamondNumTitle;
}
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.rowHeight = 56;
_tableView.scrollEnabled = NO;
_tableView.backgroundColor = [UIColor whiteColor];
[_tableView registerClass:[XPNobleCenterPayCell class] forCellReuseIdentifier:NSStringFromClass([XPNobleCenterPayCell class])];
}
return _tableView;
}
- (UIButton *)payBtn{
if(!_payBtn){
_payBtn = [UIButton new];
[_payBtn setTitle:YMLocalizedString(@"XPNobleCenterPayView3") forState:UIControlStateNormal];
[_payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_payBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
_payBtn.layer.cornerRadius = 24;
_payBtn.layer.masksToBounds = YES;
UIImage *image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0x5AECFA),UIColorFromRGB(0x9DB4FF),UIColorFromRGB(0xCF70FF)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(303, 48)];
[_payBtn setBackgroundImage:image forState:UIControlStateNormal];
[_payBtn addTarget:self action:@selector(payBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _payBtn;
}
- (NSArray *)listData{
if(!_listData){
_listData = @[YMLocalizedString(@"XPNobleCenterPayView2")];
}
return _listData;
}
- (UIButton *)backBtn{
if(!_backBtn){
_backBtn = [UIButton new];
[_backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
}
return _backBtn;
}
@end