2010-10-18 54 views

回答

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 
} 

编码快乐......

+0

感谢您的帮助:) – 2010-10-18 05:59:48

+0

获得投票是最好的感谢:P – 2010-10-18 06:20:29

0

我敢肯定有解决这个问题的一个非哈克的方式。我建议寻找关联inputAccessoryView与您的文本字段。