Wallet包

作者: 香蕉你个菠萝 | 来源:发表于2018-05-25 16:17 被阅读6次

    YLWalletViewController.h

    #import "YLWalletViewController.h"
    #import "YLWalletMainView.h"
    #import "YLWalletViewModel.h"
    #import "YLWithdrawViewController.h"//提现
    #import "YLRechargeViewController.h"
    #import "YLBalanceDetailsViewController.h"
    
    #import "YLCardManageViewController.h"
    
    @interface YLWalletViewController ()
    @property (nonatomic,strong) YLWalletMainView *mainView;
    @property (nonatomic,strong) YLWalletViewModel *viewModel;
    @end
    
    @implementation YLWalletViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        self.title = @"钱包";
    }
    
    -(void)bindViewModel {
        WS(weakSelf)
        [[self.viewModel.cellClickSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString *  _Nullable x) {
            NSInteger index = [x integerValue];
            switch (index) {
                case 0:
                {//chongzhi
                    YLRechargeViewController * YVC = [[YLRechargeViewController alloc] init];
                    [weakSelf.navigationController pushViewController:YVC animated:YES];
                }
                    break;
                case 1:
                {//mingxi
                    YLBalanceDetailsViewController * BVC = [[YLBalanceDetailsViewController alloc] init];
                    [weakSelf.navigationController pushViewController:BVC animated:YES];
                }
                    break;
                case 2:
                {//bangding
                    
                }
                    break;
                case 3:
                {//kaguanli
                    YLCardManageViewController * BVC = [[YLCardManageViewController alloc] init];
                    [weakSelf.navigationController pushViewController:BVC animated:YES];
                }
                    break;
                    
                default:
                    break;
            }
        }];
    }
    -(void)rightClick {
        YLWithdrawViewController * WVC = [[YLWithdrawViewController alloc] init];
        [self.navigationController pushViewController:WVC animated:YES];
    }
    
    
    -(UIBarButtonItem *)rightButton {
        UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 43, 23)];
        [btn setTitle:@"提现" forState:UIControlStateNormal];
        btn.titleLabel.textAlignment = NSTextAlignmentRight;
        [btn setTitleColor:RGB(51, 51, 51) forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:15.0f];
        [btn setBackgroundColor:[UIColor clearColor]];
        [btn addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
        return [[UIBarButtonItem alloc] initWithCustomView:btn];
    }
    -(void)addChildView {
        [self.view addSubview:self.mainView];
    }
    
    -(void)updateViewConstraints {
        [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view);
        }];
        [super updateViewConstraints];
    }
    -(YLWalletViewModel *)viewModel {
        if (!_viewModel) {
            _viewModel = [[YLWalletViewModel alloc] init];
        }
        return _viewModel;
    }
    -(YLWalletMainView *)mainView {
        if (!_mainView) {
            _mainView = [[YLWalletMainView alloc] initWithViewModel:self.viewModel];
        }
        return _mainView;
    }
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    /*
    #pragma mark - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */
    
    @end
    
    

    YLWalletMainView.h

    //
    //  YLWalletMainView.m
    //  DXYiGe
    //
    //  Created by JHT on 2018/5/23.
    //  Copyright © 2018年 QC. All rights reserved.
    //
    
    #import "YLWalletMainView.h"
    #import "YLWalletViewModel.h"
    #import "YLWalletCell.h"
    #import "YLWalletHeadView.h"
    
    @interface YLWalletMainView()<UITableViewDataSource,UITableViewDelegate>
    @property (nonatomic,strong) YLWalletViewModel *viewModel;
    @property (nonatomic,strong) UITableView *tableView;
    @property (nonatomic,strong) YLWalletHeadView *headView;
    @property (nonatomic,strong) NSArray *titleArr;
    @end
    
    @implementation YLWalletMainView
    
    -(instancetype)initWithViewModel:(id<BaseViewModelProtocol>)viewModel {
        self.viewModel = (YLWalletViewModel *)viewModel;
        return [super initWithViewModel:self.viewModel];
    }
    -(void)bindViewModel {
        
    }
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 2;
    }
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        if (section == 0) {
            return 2;
        }else return 2;
    }
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return 60;
    }
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSString * row;
        if (indexPath.section == 0) {
            row = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
        }else {
            row = [NSString stringWithFormat:@"%ld",(long)indexPath.row+2];
        }
        [self.viewModel.cellClickSubject sendNext:row];
        NSLog(@"cellclick->%@",row);
    }
    
    -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section {
        return 10;
    }
    
    -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
        view.backgroundColor = RGB(240, 240, 240);
        return view;
    }
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        YLWalletCell * cell  = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithUTF8String:object_getClassName([YLWalletCell class])]];
        
        if (indexPath.section == 0) {//0 1
            cell.nameLabel.text = self.titleArr[indexPath.row];
            cell.imgView.image = [UIImage imageNamed:self.titleArr[indexPath.row]];
        }else {
            cell.nameLabel.text = self.titleArr[indexPath.row+2];
            cell.imgView.image = [UIImage imageNamed:self.titleArr[indexPath.row+2]];
        }
        return cell;
    }
    
    
    -(UITableView *)tableView{
        if (!_tableView) {
            _tableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
            _tableView.delegate = self;
            _tableView.dataSource = self;
            _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            [_tableView registerClass:[YLWalletCell class] forCellReuseIdentifier:[NSString stringWithUTF8String:object_getClassName([YLWalletCell class])]];
            _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            
            self.headView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 171);
            [_tableView setTableHeaderView:self.headView];
            
            _tableView.backgroundColor = RGB(240, 240, 240);
        }
        return _tableView;
    }
    -(NSArray *)titleArr {
        if (!_titleArr) {
            _titleArr = [NSArray arrayWithObjects:@"充值",@"余额明细",@"账户绑定",@"银行卡管理", nil];
        }
        return _titleArr;
    }
    
    -(YLWalletHeadView *)headView {
        if (!_headView) {
            _headView = [[YLWalletHeadView alloc] initWithViewModel:self.viewModel];
            _headView.backgroundColor = RGB(255, 218, 68);
        }
        return _headView;
    }
    -(void)setupViews {
        [self addSubview:self.tableView];
        [self setNeedsUpdateConstraints];
        [self updateConstraintsIfNeeded];
    }
    -(void)updateConstraints {
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        [super updateConstraints];
    }
    - (YLWalletViewModel *)viewModel {
        if (!_viewModel) {
            _viewModel = [[YLWalletViewModel alloc] init];
        }
        return _viewModel;
    }
    
    @end
    
    

    YLWalletHeadView.h

    //
    //  YLWalletHeadView.m
    //  DXYiGe
    //
    //  Created by JHT on 2018/5/23.
    //  Copyright © 2018年 QC. All rights reserved.
    //
    
    #import "YLWalletHeadView.h"
    #import "YLWalletViewModel.h"
    
    @interface YLWalletHeadView ()
    @property (nonatomic,strong) YLWalletViewModel *viewModel;
    @property (nonatomic,strong) UILabel *topLabel;
    @property (nonatomic,strong) UILabel *moneyLabel;
    @end
    
    @implementation YLWalletHeadView
    -(instancetype)initWithViewModel:(id<BaseViewModelProtocol>)viewModel {
        self.viewModel = (YLWalletViewModel *)viewModel;
        return [super initWithViewModel:self.viewModel];
    }
    -(void)bindViewModel {
        
    }
    -(void)setupViews {
        [self addSubview:self.topLabel];
        [self addSubview:self.moneyLabel];
        
        [self setNeedsUpdateConstraints];
        [self updateConstraintsIfNeeded];
    }
    -(void)updateConstraints {
        [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(35);
            make.centerX.equalTo(self);
        }];
        [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topLabel.mas_bottom).offset(20);
            make.centerX.equalTo(self);
        }];
        
        [super updateConstraints];
    }
    -(UILabel *)moneyLabel {
        if (!_moneyLabel) {
            _moneyLabel = [[UILabel alloc] init];
            _moneyLabel.font = [UIFont systemFontOfSize:50];
            _moneyLabel.textColor = RGB(51, 51, 51);
            _moneyLabel.text = @"0";
            _moneyLabel.textAlignment = NSTextAlignmentCenter;
        }
        return _moneyLabel;
    }
    -(UILabel *)topLabel {
        if (!_topLabel) {
            _topLabel = [[UILabel alloc] init];
            _topLabel.font = [UIFont systemFontOfSize:15];
            _topLabel.textColor = RGB(51, 51, 51);
            _topLabel.text = @"账户余额(元)";
            _topLabel.textAlignment = NSTextAlignmentCenter;
        }
        return _topLabel;
    }
    - (YLWalletViewModel *)viewModel {
        if (!_viewModel) {
            _viewModel = [[YLWalletViewModel alloc] init];
        }
        return _viewModel;
    }
    
    
    @end
    
    

    YLWalletCell.h

    //
    //  YLWalletCell.m
    //  DXYiGe
    //
    //  Created by JHT on 2018/5/23.
    //  Copyright © 2018年 QC. All rights reserved.
    //
    
    #import "YLWalletCell.h"
    
    @interface YLWalletCell ()
    //@property (nonatomic,strong) UILabel *nameLabel;
    //@property (nonatomic,strong) UIImageView *imgView;
    
    @property (nonatomic,strong) UIView *line;
    @property (nonatomic,strong) UIImageView *arrowImg;
    @end
    
    @implementation YLWalletCell
    
    -(void)setupViews {
        [self addSubview:self.nameLabel];
        [self addSubview:self.imgView];
        [self addSubview:self.line];
        [self addSubview:self.arrowImg];
        
        [self setNeedsUpdateConstraints];
        [self updateConstraintsIfNeeded];
    }
    -(void)updateConstraints {
        
    
        [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self).offset(15);
            make.size.mas_offset(CGSizeMake(20, 20));
        }];
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self.imgView.mas_right).offset(15);
            make.size.mas_offset(CGSizeMake(160, 20));
        }];
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self);
            make.height.mas_equalTo(0.5f);
            make.left.equalTo(self).offset(15);
            make.right.equalTo(self).offset(-15);
        }];
        
        [self.arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.right.equalTo(self).offset(-15);
            make.size.mas_offset(CGSizeMake(8, 15));
        }];
    
        [super updateConstraints];
        
    }
    
    -(UIImageView *)arrowImg {
        if (!_arrowImg) {
            if (!_arrowImg) {
                _arrowImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"personal_go"]];// 8*15
            }
        }
        return _arrowImg;
    }
    -(UIView *)line {
        if (!_line) {
            _line = [[UIView alloc] init];
            _line.backgroundColor = RGB(240, 240, 240);
        }
        return _line;
    }
    
    -(UILabel *)nameLabel {
        if (!_nameLabel) {
            _nameLabel = [[UILabel alloc] init];
            _nameLabel.text = @"****";
            _nameLabel.font = [UIFont systemFontOfSize:14.0f];
            _nameLabel.textColor = RGB(51, 51, 51);
        }
        return _nameLabel;
    }
    -(UIImageView *)imgView {
        if (!_imgView) {
            _imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"weixin"]];
            _imgView.contentMode = UIViewContentModeScaleAspectFill;
        }
        return _imgView;
    }
    - (void)awakeFromNib {
        [super awakeFromNib];
        // Initialization code
    }
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
        [super setSelected:selected animated:animated];
    
        // Configure the view for the selected state
    }
    
    @end
    
    

    相关文章

      网友评论

          本文标题:Wallet包

          本文链接:https://www.haomeiwen.com/subject/nihujftx.html