在iPhone的虚拟键盘中添加新按钮?
如何将新按钮添加到iPhone的虚拟键盘(触摸UITextField时显示的键盘)?以下是我在键盘左下角添加“完成”按钮的代码在iPhone的虚拟键盘中添加新按钮?,iphone,objective-c,ios,Iphone,Objective C,Ios,如何将新按钮添加到iPhone的虚拟键盘(触摸UITextField时显示的键盘)?以下是我在键盘左下角添加“完成”按钮的代码 - (void)keyboardWillShow:(NSNotification *)note { // create custom button UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; doneButton.frame = CGRectMake(0
- (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
}
你需要做的是接受This的想法,在键盘上的任何位置设置你的按钮
- (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
}
-(无效)键盘将显示:(NSNotification*)注释{
//创建自定义按钮
UIButton*doneButton=[UIButton按钮类型:UIButtonTypeCustom];
doneButton.frame=CGRectMake(0,163,106,53);
doneButton.adjustsImageWhenHighlighted=否;
[完成按钮设置标题:@“完成”状态:UIControlStateNormal];
//[doneButton setImage:[UIImage ImageName:@“DoneUp.png”]用于状态:UIControlStateNormal];
//[doneButton setImage:[UIImage ImageName:@“DoneDown.png”]用于状态:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:)for ControlEvents:UIControlEventTouchUpInside];
//定位键盘视图
UIWindow*tempWindow=[[UIApplication sharedApplication]windows]对象索引:1];
对于(inti=0;i,我非常确定有一种非黑客的方法可以解决这个问题。我建议您研究将一个与您的文本字段关联起来