你需要使用 textfied 的 inputAccessoryView 属性
txtfld.keyboardType=UIKeyboardTypeDecimalPad;
txtfld.inputAccessoryView=[self toolBarForKeyboardAccessory];
接着
-(UIToolbar *)toolBarForKeyboardAccessory
{
UIToolbar *keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
keyboardToolbar.barStyle = UIBarStyleDefault;
UIBarButtonItem* flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonClicked:)];
CGRect rect = CGRectMake(1, 5.0, 250, 30);
KeyboardTextField = [[UITextField alloc] initWithFrame:rect];
KeyboardTextField.borderStyle = UITextBorderStyleRoundedRect;
KeyboardTextField.font = [UIFont systemFontOfSize:17.0];
KeyboardTextField.delegate = self;
UIBarButtonItem *textFieldItem = [[UIBarButtonItem alloc] initWithCustomView:KeyboardTextField] ;
[keyboardToolbar setItems:[NSArray arrayWithObjects: flexSpace,textFieldItem,flexSpace, cancelButton,flexSpace, nil] animated:NO];
return keyboardToolbar;
}