iOS支付数字键盘(仿支付宝,可自定义)

效果图如下:

支付数字键盘gif

现在大部分的app可能都会碰到自定义键盘这种需求,特别是一些金融类的APP,在涉及到输入金额的时候,都会用到自定义键盘。今天就封装了一个仿支付宝的支付数字键盘,并且提供了更多供用户自定义的接口,用户可自定义键盘大部分内容。如背景色,字体颜色,return键的回调,输出内容格式(如000.00)等
逻辑图如下:

iOS支付数字键盘(仿支付宝,可自定义)_第1张图片

使用方法:

1.属性
/// 文本框
@property (nonatomic, weak) UITextField *textFiled;
/// 点击确定回调block
@property (nonatomic,copy) ConfirmBlock confirmClickBlock;
/// 键盘背景色
@property (nonatomic,strong) UIColor *bgColor;
/// 键盘数字背景色
@property (nonatomic,strong) UIColor *keyboardNumBgColor;
/// 键盘文字颜色
@property (nonatomic,strong) UIColor *keyboardTitleColor;
/// 间隔线颜色
@property (nonatomic,strong) UIColor *marginColor;
/// return键被背景色
@property (nonatomic,strong) UIColor *returnBgColor;
/// return键文字颜色
@property (nonatomic,strong) UIColor *returnTitleColor;
/// return键title
@property (nonatomic,strong) NSString *title;
/// 输出内容格式(00000.00)
@property (nonatomic,strong) NSString *formatString;
/// 绘制键盘
- (void)drawKeyboard;
2.简单使用
- (void)showMoneyKeyboard
{
    YLNumberKeyboard *keyboard = [[YLNumberKeyboard alloc]init];
    // 指定哪个textfield需要弹出数字键盘
    keyboard.textFiled = self.textField;
    self.textField.inputView = keyboard;
    // 个性化设置键盘
    keyboard.bgColor = YLRandomColor;
    keyboard.returnBgColor = YLRandomColor;
    keyboard.returnTitleColor = YLRandomColor;
    keyboard.formatString = @"000.000";
    __weak YLNumberKeyboard *keyboard1 = keyboard;
    keyboard.confirmClickBlock = ^{
       UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"要求的格式为%@  输入的数字为%@",keyboard1.formatString,self.textField.text] preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:^{
            
        }];
    };
    // 绘制键盘
    [keyboard drawKeyboard];
    
}

具体使用可参看demo,地址支付数字键盘demo
如果喜欢的话,顺便给个星哦

你可能感兴趣的:(iOS支付数字键盘(仿支付宝,可自定义))