默认的数字键盘没有Done按键,如下图:
KeyboardViewController.h
#import <UIKit/UIKit.h>
@interface KeyboardViewController: UIViewController {
UITextField *textField;
}
@end
KeyboardViewController.m
#import "KeyboardViewController.h"
@implementation KeyboardViewController
- (void)loadView {
self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 26)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.keyboardType = UIKeyboardTypeNumberPad;
textField.returnKeyType = UIReturnKeyDone;
textField.textAlignment = UITextAlignmentLeft;
textField.text = @"12345";
[self.view addSubview:textField];
[textField release];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardDidShowNotification
object:nil];
}
- (void)keyboardWillShow:(NSNotification *)note {
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
UIWindow *tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView *keyboard;
for(int i = 0; i < [tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
if(([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES) || ([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES))
[keyboard addSubview:doneButton];
}
}
- (void)doneButton:(id)sender {
[textField resignFirstResponder];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[textField release];
[super dealloc];
}
@end
效果图:
分享到:
相关推荐
自定义数字键盘 iphone4 xcode4.1 添加DONE按钮
linear algebra done wrong
专为中小学教育开发打造的3D设计软件--3DOne,致力于学生思维能力的提高,实现创新素质教育的发展。因此,3DOne具备简单易用的程序环境,支持专业级的涂鸦式平面草图绘制,可进行丰富实用的3D实体设计,提供多种多样...
我们在android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“GO”按键加载url页面;在点击搜索框的时候,点击右下角的search符号键可以进行搜索;或者在...
3done实体设计案例:杯子制作.pdf
3Done 入门课程《矿泉水瓶》制作
Verilog HDL语言实现按键消抖 assign key_done = (dout1 | dout2 | dout3); //按键消抖输出
对于$.ajax请求来说,如果层级比较多,程序看起来会比较乱,而为了解决这种问题,才有了$when…done…fail…then的封装,它将$.ajax这嵌套结构转成了顺序平行的结果,向下面的$.ajax写法,看起来很乱 $.ajax({ url...
Linear algebra done right是一本很经典的线性代数入门教材
3D建模
3Done 入门课程《葫芦》制作
现在的许多3done版本是需要烦人的用户登录的,在使用中会感觉许多不方便,所以在网络上找了许久终于发现这个不需要用户名登录的版本,希望能让你愉快的进行,3d模型编辑
Statistics Done Wrong is a pithy, essential guide to statistical blunders in modern science that will show you how to keep your research blunder-free. You'll examine embarrassing errors and omissions ...
分析FPGA的DONE上拉电阻阻值与启动关系
3Done-帆船的制作教程.pdf
5初识3Done.docx 6饼干模具.docx 7创意书签.docx 8小椅子.docx 9花瓶.docx 10小茶杯.docx 11卡通手机架.docx 12立式笔筒.docx 13小印章.docx 14楼空垃圾桶.docx 15小能牙刷架.docx 16地球仪.docx 17飞机模型.docx 18...
Liner Algebra Done Right
Get things done英文版,好书啊
Linear Algebra Done Right一本很有趣的高等代数讲义,比国内大学的高等代数深一些,但是看起来很简单
3Done 入门课程《 创意笔筒》制作