iOS自定义键盘

iOS自定义键盘 如果项目中有特定的输入需求,例如 银行类、金融类、交易类App,对输入的安全性要求较高 因此需要通过自定义键盘进行操作,可以提高用户的安全性。

github地址: https://github.com/yadottoday/QHKeyboard

核心代码:

#import "QHKeyboard.h"
#import "QHKeyboardNumPad.h"
#import "QHKeyboardWordPad.h"

#define  iPhone4     ([[UIScreen mainScreen] bounds].size.height==480)
#define  iPhone5     ([[UIScreen mainScreen] bounds].size.height==568)
#define  iPhone6     ([[UIScreen mainScreen] bounds].size.height==667)
#define  iPhone6plus ([[UIScreen mainScreen] bounds].size.height==736)


@interface QHKeyboard ()<QHKeyboardNumPadDelegate,QHKeyboardWordPadDelegate>

@property (nonatomic, weak) QHKeyboardNumPad *numPad;
@property (nonatomic, weak) QHKeyboardWordPad *wordPad;

@end

@implementation QHKeyboard

- (instancetype)init {
   
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:116/255.0 green:144/255.0 blue:194/255.0 alpha:0.2];
        CGRect rect = CGRectZero;
        if (iPhone4 || iPhone5) {
            //            rect = CGRectMake(0, 0, 320, 180);
            rect = CGRectMake(0, 0, 320, 216);
        }else if (iPhone6){
            //            rect = CGRectMake(0, 0, 375, 375/320*180);
            rect = CGRectMake(0, 0, 375, 216);
        }else{
            //            rect = CGRectMake(0, 0, 414, 414/320*180);
            rect = CGRectMake(0, 0, 414, 226);
        }
        
        self.frame = rect;
        QHKeyboardNumPad *numPad = [[QHKeyboardNumPad alloc] initWithFrame:rect];
        numPad.delegate = self;
        self.numPad = numPad;
        [self addSubview:numPad];
    }
    return self;
}

- (void)KeyboardNumPadDidClickSwitchBtn:(UIButton *)btn {
    
    if ([btn.titleLabel.text isEqualToString:@"ABC"]) {
        QHKeyboardWordPad *wordPad = [[QHKeyboardWordPad alloc] initWithFrame:self.bounds];
        wordPad.delegate = self;
        [self addSubview:wordPad];
        self.wordPad = wordPad;
        [self.numPad removeFromSuperview];
    }
}

- (void)KeyboardWordPadDidClickSwitchBtn:(UIButton *)btn {
   
    if ([btn.titleLabel.text isEqualToString:@"123"]) {
        
        QHKeyboardNumPad *numPad = [[QHKeyboardNumPad alloc] initWithFrame:self.bounds];
        numPad.delegate = self;
        [self addSubview:numPad];
        self.numPad = numPad;
        [self.wordPad removeFromSuperview];
    }
}

- (void)KeyboardSymbolPadDidClickSwitchBtn:(UIButton *)btn {
    
    if ([btn.titleLabel.text isEqualToString:@"123"]) {
        
        QHKeyboardNumPad *numPad = [[QHKeyboardNumPad alloc] initWithFrame:self.bounds];
        numPad.delegate = self;
        [self addSubview:numPad];
        self.numPad = numPad;
        
    } else {
        
        QHKeyboardWordPad *wordPad = [[QHKeyboardWordPad alloc] initWithFrame:self.bounds];
        wordPad.delegate = self;
        [self addSubview:wordPad];
        self.wordPad = wordPad;
    }
}
如图:



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值