【发布时间】:2014-03-13 21:42:57
【问题描述】:
iOS 中的标准键盘确实有一个返回键,并且有一个委托方法,当用户点击返回键时会调用该方法。
数字键盘上可以有返回键吗?
【问题讨论】:
标签: ios uitextfield
iOS 中的标准键盘确实有一个返回键,并且有一个委托方法,当用户点击返回键时会调用该方法。
数字键盘上可以有返回键吗?
【问题讨论】:
标签: ios uitextfield
你可以这样做,你可以设置你自己的工具栏位置。
- (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];
}
【讨论】:
没有办法修改标准数字键盘。典型的解决方案是设置一个带有按钮的工具栏,并将此视图设为文本字段的inputAccessoryView。然后在点击按钮时在文本字段上调用resignFirstResponder。
【讨论】:
UIPickerView 作为inputView。 inputAccessoryView 显示在键盘顶部(或 inputView)。
inputView。我一直在查看我在互联网上找到的一些示例,它们包含大量代码,只是为了在数字键盘顶部显示一个返回键。你有一个简短示例的链接吗?
inputAccessoryView。没什么大不了的。