数字键盘添加自定义按钮
2013-06-08 10:14
477 查看
项目需要对数字键盘做个性化设置,网上找了几个例子,学习了下,然后总结了一下:
数字键盘
身份证键盘
主要的代码如下
1.- (void)addButtonToKeyboardWithSelector:(SEL)sel normal:(UIImage*)nimg highlight:(UIImage*)himg{
2. // create custom button
3. UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
4. doneButton.tag=8;
5. doneButton.frame = CGRectMake(0, 0, 106, 53);
6. doneButton.adjustsImageWhenHighlighted = NO;
7.
8. [doneButton setImage:nimg forState:UIControlStateNormal];
9. [doneButton setImage:himg forState:UIControlStateHighlighted];
10. [doneButton addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
11. // locate keyboard view
12. int cnt=[[UIApplication sharedApplication] windows].count;
13. UIWindow* keyboardWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:cnt-1];
14. doneButton.frame = CGRectMake(0, keyboardWindow.frame.size.height-53, 106, 53);
15. [keyboardWindow addSubview:doneButton];
16.
17. NSLog(@"keyboard:%@ %@ %@",NSStringFromCGRect(keyboardWindow.frame),NSStringFromCGRect(doneButton.frame),keyboardWindow.subviews);
18.}
19.
20.- (void)removeButtonFromKeyboard {
21. // locate keyboard view
22. int cnt=[[UIApplication sharedApplication] windows].count;
23. UIWindow* keyboardWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:cnt-1]; 23.24.[[keyboardWindow viewWithTag:8] removeFromSuperview];
25.}
示例代码:
doneButton.zip
(332 K)
原帖地址:http://www.cocoachina.com/bbs/read.php?tid=140742
数字键盘
身份证键盘
主要的代码如下
1.- (void)addButtonToKeyboardWithSelector:(SEL)sel normal:(UIImage*)nimg highlight:(UIImage*)himg{
2. // create custom button
3. UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
4. doneButton.tag=8;
5. doneButton.frame = CGRectMake(0, 0, 106, 53);
6. doneButton.adjustsImageWhenHighlighted = NO;
7.
8. [doneButton setImage:nimg forState:UIControlStateNormal];
9. [doneButton setImage:himg forState:UIControlStateHighlighted];
10. [doneButton addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
11. // locate keyboard view
12. int cnt=[[UIApplication sharedApplication] windows].count;
13. UIWindow* keyboardWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:cnt-1];
14. doneButton.frame = CGRectMake(0, keyboardWindow.frame.size.height-53, 106, 53);
15. [keyboardWindow addSubview:doneButton];
16.
17. NSLog(@"keyboard:%@ %@ %@",NSStringFromCGRect(keyboardWindow.frame),NSStringFromCGRect(doneButton.frame),keyboardWindow.subviews);
18.}
19.
20.- (void)removeButtonFromKeyboard {
21. // locate keyboard view
22. int cnt=[[UIApplication sharedApplication] windows].count;
23. UIWindow* keyboardWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:cnt-1]; 23.24.[[keyboardWindow viewWithTag:8] removeFromSuperview];
25.}
示例代码:
doneButton.zip
(332 K)
原帖地址:http://www.cocoachina.com/bbs/read.php?tid=140742
相关文章推荐
- 为数字键盘添加自定义按钮的方法(iOS所有版本适用
- 数字键盘添加自定义按钮(转自cocoachina)
- iOS8 数字键盘添加自定义按钮(兼容各个版本以及解决自定义按钮滑动出现的问题)
- 为数字键盘添加自定义按钮的方法
- 数字键盘添加自定义按钮
- UIKeyboardTypeNumberPad 数字键盘添加完成按钮
- iOS8数字键盘左下角添加完成按钮的核心代码如下:
- 1怎样让输入的text文本填写的部分只添加数字、2怎样将输入的数字一次性全部删除 3怎样选择密码 让它不显示 4 怎样实现在没有return的情况下点击button的情况下就能够使键盘页面下落5 怎样实现点击指定的button来对使指定的text进行键盘弹出 6怎样改变button按钮的状态
- 给数字键盘添加完成按钮的坑
- IOS数字键盘左下角添加完成按钮的实现方法
- ios隐藏数字键盘 --在数字键盘左下角添加“完成”按钮的实现原理
- iOS 数字输入键盘添加一个完成按钮
- (判断第三方输入法)在系统数字键盘上添加“完成”按钮引发的问题思考
- iOS8数字键盘左下角添加完成按钮
- ios在数字键盘左下角添加“完成”按钮的实现原理
- ios在数字键盘左下角添加“完成”按钮的实现原理
- 数字键盘添加“完成”按钮
- 键盘 添加自定义按钮
- iOS开发系列之常用自定义控件开发集—自定义数字键盘控件开发
- FCKeditor添加自定义按钮