0
如何在iPhone的虛擬鍵盤中添加新按鈕(觸摸UITextField時出現的鍵盤)?將新按鈕添加到iPhone的虛擬鍵盤?
如何在iPhone的虛擬鍵盤中添加新按鈕(觸摸UITextField時出現的鍵盤)?將新按鈕添加到iPhone的虛擬鍵盤?
繼承人我已經在鍵盤的左下角添加了一個完成按鈕的代碼。
你需要做的是從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
}
編碼快樂......
我敢肯定有解決這個問題的一個非哈克的方式。我建議尋找關聯inputAccessoryView與您的文本字段。
感謝您的幫助:) – 2010-10-18 05:59:48
獲得投票是最好的感謝:P – 2010-10-18 06:20:29