ZCWithdrawInputCell.m 4.44 KB
Newer Older
zhukai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
//
//  ZCWithdrawInputCell.m
//  UniversalApp
//
//  Created by 凯朱 on 2019/6/2.
//  Copyright © 2019 徐阳. All rights reserved.
//

#import "ZCWithdrawInputCell.h"
#import "ZCWithdrawModel.h"
@interface ZCWithdrawInputCell()<UITextFieldDelegate>

@end

@implementation ZCWithdrawInputCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [_inputTextField.subviews[0] removeFromSuperview];
    //监听textField变化
    [_inputTextField addTarget:self action:@selector(inputTextFieldChangeAction) forControlEvents:UIControlEventEditingChanged];
    _inputTextField.font = kFont(49);
    [_inputTextField setValue:KColor_3 forKeyPath:@"_placeholderLabel.textColor"];
    [_inputTextField setValue:kFont(15) forKeyPath:@"_placeholderLabel.font"];
    _inputTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputTextField.delegate = self;
    _inputTextField.keyboardType = UIKeyboardTypeDecimalPad;
}

-(void)paddingWithModel:(ZCWithdrawModel *)model{
    //有输入提现金额
ChenCD committed
32 33
    _balanceLbl.text = [NSString stringWithFormat:@"可用余额 %.2f元",[kUserInfo.money doubleValue]];
    _balanceLbl.font = kFont(12);
zhukai committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
    _inputTextField.text = kSTRING(model.withdrawMoney);
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(nonnull NSString *)string{
    //是否已经有小数点
    BOOL isHaveDian = YES;
    if ([textField.text rangeOfString:@"."].location == NSNotFound) {
        isHaveDian = NO;
    }
    //首先得是字符文案
    if ([string length] > 0) {
        unichar single = [string characterAtIndex:0];//当前输入的字符
        if ((single >= '0' && single <= '9') || single == '.') {//数据格式正确
            //首字母不能为0和小数点
            if([textField.text length] == 0){
                if(single == '.') {
                    NSLog(@"亲,第一个数字不能为小数点");
                    [textField.text stringByReplacingCharactersInRange:range withString:@""];
                    return NO;
                }
            }
            
            if ([textField.text length] == 1) {
                if (single == '0' && [textField.text isEqualToString:@"0"]) {
                    NSLog(@"亲,连续数字不能为0");
                    [textField.text stringByReplacingCharactersInRange:range withString:@""];
                    return NO;
                }
            }
            
            //输入的字符是否是小数点
            if (single == '.') {
                if(!isHaveDian)//text中还没有小数点
                {
                    isHaveDian = YES;
                    return YES;
                }else{
                    NSLog(@"亲,您已经输入过小数点了");
                    [textField.text stringByReplacingCharactersInRange:range withString:@""];
                    return NO;
                }
            }else{
                if (isHaveDian) {//存在小数点
                    //判断小数点的位数
                    NSRange ran = [textField.text rangeOfString:@"."];
                    if (range.location - ran.location <= 2) {
                        return YES;
                    }else{
                        NSLog(@"亲,您最多输入两位小数");
                        return NO;
                    }
                }
            }
        }else{//输入的数据格式不正确
            NSLog(@"亲,您输入的格式不正确");
            [textField.text stringByReplacingCharactersInRange:range withString:@""];
            return NO;
        }
    }
    else
    {
        return YES;
    }
    return YES;
}

/**
 全部提现
 */
- (IBAction)allSelectAction:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(zcWithdrawInputCellAllWithdrawAction:)]) {
        [self.delegate zcWithdrawInputCellAllWithdrawAction:self];
    }
}

/**
 输入金额
 */
-(void)inputTextFieldChangeAction{
    
    
    
    _inputTextField.font = kFont(49);
    [_inputTextField setValue:KColor_3 forKeyPath:@"_placeholderLabel.textColor"];
    [_inputTextField setValue:kFont(15) forKeyPath:@"_placeholderLabel.font"];
    
    if ([_inputTextField.text doubleValue] > [_maxMoney doubleValue]) {
        _inputTextField.text = _maxMoney;
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(zcWithdrawInputCellTextFieldChange:cell:)]) {
        [self.delegate zcWithdrawInputCellTextFieldChange:_inputTextField cell:self];
    }
}

@end