How to get keyboard with Next, Previous and Done Button?

前端 未结 8 1066
我寻月下人不归
我寻月下人不归 2020-12-02 08:55

I want to have a keyboard which has a Next,Previous and Done button on top of it.

I have seen that in many apps.

Especially where there are forms to be fille

8条回答
  •  孤街浪徒
    2020-12-02 09:49

    -(BOOL)textFieldShouldBeginEditing: (UITextField *)textField 
    
    {
         UIToolbar * keyboardToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
    
        keyboardToolBar.barStyle = UIBarStyleDefault;
        [keyboardToolBar setItems: [NSArray arrayWithObjects:
                                    [[UIBarButtonItem alloc]initWithTitle:@"Previous" style:UIBarButtonItemStyleBordered target:self action:@selector(previousTextField)],
    
                                    [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextTextField)],
                                    [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                                    [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard)],
                                    nil]];
        textField.inputAccessoryView = keyboardToolBar;
    
    }
    
    
    
    - (void)nextTextField {
    
    
        if (textField1) {
    
            [textField1 resignFirstResponder];
            [textField2 becomeFirstResponder];
    
        }
    
    }
    
    -(void)previousTextField
    {
    
        if (textField2) {
            [textField2 resignFirstResponder];
            [textField1 becomeFirstResponder];
        }
    
    
    }
    
    -(void)resignKeyboard {
    
        [textField1 resignFirstResponder];
        [textField2 resignFirstResponder];
    
    }
    

提交回复
热议问题