效果圖如下:
支付數(shù)字鍵盤gif
現(xiàn)在大部分的app可能都會(huì)碰到自定義鍵盤這種需求,特別是一些金融類的APP,在涉及到輸入金額的時(shí)候,都會(huì)用到自定義鍵盤。今天就封裝了一個(gè)仿支付寶的支付數(shù)字鍵盤,并且提供了更多供用戶自定義的接口,用戶可自定義鍵盤大部分內(nèi)容。如背景色,字體顏色,return鍵的回調(diào),輸出內(nèi)容格式(如000.00)等
邏輯圖如下:
使用方法:
1.屬性
/// 文本框
@property (nonatomic, weak) UITextField *textFiled;
/// 點(diǎn)擊確定回調(diào)block
@property (nonatomic,copy) ConfirmBlock confirmClickBlock;
/// 鍵盤背景色
@property (nonatomic,strong) UIColor *bgColor;
/// 鍵盤數(shù)字背景色
@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;
/// 輸出內(nèi)容格式(00000.00)
@property (nonatomic,strong) NSString *formatString;
/// 繪制鍵盤
- (void)drawKeyboard;
2.簡(jiǎn)單使用
- (void)showMoneyKeyboard
{
YLNumberKeyboard *keyboard = [[YLNumberKeyboard alloc]init];
// 指定哪個(gè)textfield需要彈出數(shù)字鍵盤
keyboard.textFiled = self.textField;
self.textField.inputView = keyboard;
// 個(gè)性化設(shè)置鍵盤
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:@"要求的格式為%@ 輸入的數(shù)字為%@",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,地址支付數(shù)字鍵盤demo
如果喜歡的話,順便給個(gè)星哦