iOS自定义键盘
2016-11-24 17:31
190 查看
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;
}
}
如图:
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;
}
}
如图:
相关文章推荐
- IOS自定义的数字键盘 FPNumberPadView
- ios键盘通知和自定义键盘
- ios 自定义键盘的按键音效和震动效果
- IOS开发之自定义系统弹出键盘上方的view
- IOS开发之自定义键盘
- 为数字键盘添加自定义按钮的方法(iOS所有版本适用
- IOS键盘管理和自定义键盘
- IOS自定义键盘搜索键
- iOS_22自定义键盘工具条
- ios开发中自定义键盘
- IOS开发之自定义系统弹出键盘上方的view(转载)
- ios键盘通知和自定义键盘
- IOS开发之自定义系统弹出键盘上方的view(转载)
- iOS开发之自定义表情键盘(组件封装与自动布局)
- ios键盘通知和自定义键盘
- iOS - 键盘自定义:
- ios之键盘的自定义
- ios键盘通知和自定义键盘
- 【iOS开发-65】QQ聊天界面案例:自定义cell、图片拉伸处理、NSNotification通知、键盘与视图移动以及输入框左边缩进处理
- [IOS]App Extension编程指南(iOS8/OS X v10.10):扩展类型--自定义键盘