views:

26

answers:

1

How to add new button into virtual keybroad of iphone ( keybroad appear when you touch UITextField)?

+1  A: 

Heres the code in which I have added a done button on the left-bottom corner of the keyboard.

What you need to do is to take the idea from thiis and set your button wherever you want on the keyboard.

- (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
}

hAPPY cODING...

Suriya
Thanks for your help :)
leduchuy89vn
Getting a vote is the best thanks :P
Suriya