iPhone 自定义键盘按键
2011-11-09 23:43
288 查看
首先注册消息通知UIKeyboardWillShowNotification :
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
在消息回叫函数中处理--添加按键
- (void)keyboardWillShow:(NSNotification *)note {
// create custom button
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];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES){
[keyboard addSubview:doneButton]; //控件 也是view 又可以分成多个控件单元 入tableView cell
break;
}
}
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; - (IBAction)keyboardWillHide:(NSNotification *)note { // 做自己要做的事情 } |
- (void)keyboardWillShow:(NSNotification *)note {
// create custom button
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];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES){
[keyboard addSubview:doneButton]; //控件 也是view 又可以分成多个控件单元 入tableView cell
break;
}
}
}
相关文章推荐
- iPhone 自定义键盘按键
- 关于Karabiner(was keyremap4macbook) Mac环境自定义键盘按键映射的利器
- iphone弹出键盘部分按键禁用
- iOS开发之UIKeyboardTypeNumberPad数字键盘自定义按键
- ios 自定义键盘的按键音效和震动效果
- iphone开发笔记(-) 退回输入键盘:自定义颜色:隐藏状态栏:
- iPhone开发笔记 退回输入键盘:自定义颜色:隐藏状态栏:
- IOS 在键盘顶部添加自定义按键
- UIKeyboardTypeNumberPad 数字键盘自定义按键
- UIKeyboardTypeNumberPad 数字键盘自定义按键
- iOS数字键盘自定义按键
- iPhone自定义键盘
- QT4 键盘按键发送自定义信号
- iPhone键盘自定义及通知
- iphone 自定义键盘(转)
- Ubuntu 14.04 下通过 XKB 修改键盘映射, 实现自定义按键
- iPhone开发笔记 退回输入键盘:自定义颜色:隐藏状态栏:
- iOS 自定义键盘+表情布局实现
- F5与ctrl+R键盘按键控制
- iOS自定义键盘输入样式(设置成时间选择器等)