如何在iPhone的虚拟键盘中添加新按钮(触摸UITextField时出现的键盘)?
答案 0 :(得分:1)
下面是我在键盘左下角添加了一个完成按钮的代码。
您需要做的是从thiis中获取想法,并在键盘上的任何位置设置按钮。
- (void)keyboardWillShow:(NSNotification *)note {
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
//[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];
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)
{
if(isNumPad==YES)
{
//[keyboard addSubview:doneButton];
}
else
{
[doneButton removeFromSuperview];
}
}
else
{
[doneButton removeFromSuperview];
}}
}
- (void)doneButton:(id)sender
{
//YOUR CODE ON DONE BUTTON CLICKED
}
快乐的编码......
答案 1 :(得分:0)
我非常确定有一种解决这个问题的非黑客方法。我建议您考虑将inputAccessoryView与您的文字字段相关联。