iOS 自定义数字键盘和计算器

iOS 自定义数字键盘和计算器_第1张图片
customKeyboard.gif

一、CustomKeyboardView :显示的键盘view
二、keyModel:键盘model,定义键盘字母枚举类型, 存储键盘上btn显示的数据源。
三、KeyboardModeHandler:为处理各种类型键盘数据源,即为MVVM中的ViewModel层。
四、KeyBoardCell:自定义键盘cell,定义键盘操作枚举类型(输入数字、输入小数点、输入运算符等)。
五、WaterFallLayout:键盘的瀑布流。

六、使用
UITextField 和 UITextView 添加自定义键盘

    CustomKeyboardView *keyBoardView = [[CustomKeyboardView alloc] initWithKeyboardType:sender.tag inputSource:_tf];
    keyBoardView.inputText = _tf.text;
     _tf.inputView = keyBoardView;
    keyBoardView.closeKeyboardBlock = ^{
        //TODO
        [_tf resignFirstResponder];
    };
    keyBoardView.confirmBlock = ^{
        //TODO
        [_tf resignFirstResponder];
    };

UISearchBar 添加自定义键盘

UITextField *searchTF = [_searchBar valueForKeyPath:@"_searchField"];
       CustomKeyboardView *keyboardView = [[CustomKeyboardView alloc] initWithKeyboardType:KeyBoardTypeNormal inputSource:searchTF];

    searchTF.inputView = keyboardView;
    keyboardView.closeKeyboardBlock = ^{
       //TODO
        [_searchBar resignFirstResponder];
forState:UIControlStateNormal];
    };
    keyboardView.confirmBlock = ^{
        //TODO
        [_searchBar resignFirstResponder];
    };

七、注意点:记得实现UITextFieldDelegate代理方法

- (BOOL)textField:(UITextField *)textField 
shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    return YES;
}

链接:CustomKeyboardView

参考:https://www.jianshu.com/p/b3e97fb70021

你可能感兴趣的:(iOS 自定义数字键盘和计算器)