2014-03-13 29 views

回答

0

无法修改标准数字键盘。典型的解决方案是使用按钮设置工具栏,并使该视图成为文本字段的inputAccessoryView。点击按钮后,您可以在文本框中调用resignFirstResponder

+0

@maddy工具栏显示哪里?我一直在使用pickerview作为另一个项目中的inputAccessoryView,并且pickerview显示的不是textview的键盘。但我不需要带按钮而不是键盘的工具栏,我需要两个显示。你有没有尝试过? – mrd

+0

我想你的意思是你一直在使用'UIPickerView'作为'inputView'。 'inputAccessoryView'显示在键盘的顶部(或'inputView')。 – rmaddy

+0

对,我的错,它是'inputView'。我一直在寻找我在互联网上找到的一些例子,它们包含大量的代码,只在数字键盘上显示返回键。你有链接到一个简短的例子吗? – mrd

2

你可以这样做,你可以设置你自己的工具栏的位置。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    if(textField == yourTextField) 
    { 
     UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; 
     numberToolbar.barStyle = UIBarStyleBlackTranslucent; 
     numberToolbar.items = [NSArray arrayWithObjects: 
           [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], 
           [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], 
           [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButton)],nil]; 
     textField.inputAccessoryView = numberToolbar; 
} 
} 

- (void)doneButton 
{ 
    [youtTextField resignFirstResponder]; 
}