![](/img/trans.png)
[英]iPhone keyboard in UIWebView, how to change the language of next/previous and done buttons
[英]How to get keyboard with Next, Previous and Done Button?
我想要一个键盘,它上面有一个Next,Previous和Done按钮。
我在许多应用程序中看到过这一点。
特别是有形式需要填写的地方。
我想实现与键盘上面类似的东西
我怎么能得到它?
你会在另一篇文章中找到答案。 我检查了iOS库,UITextField的inputAccessoryView正是你要找的!
希望这可以帮助 !
我刚刚创建了一个名为BSKeyboardControls
的类,这使得将控件添加到键盘非常容易。 可以在GitHub上找到类,指令和示例代码。
这些控件适用于文本字段和文本视图,并针对iPhone和iPad进行了优化。
-(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];
}
我有一个实用程序类,基本上为你做这个。
https://github.com/kalvish21/CustomKeyboard
这个想法非常简单。 您必须添加一个带有条形按钮项的附件工具栏。 有一个委托,它定义了该按钮的作用。
https://github.com/hackiftekhar/IQKeyboardManager
这是迄今为止我见过的最好的键盘处理程序。 管理文本输入的非常好的方法。
它的一些功能1)ZERO LINE OF CODE
2)自动工作
3)没有更多的UIScrollView
4)没有更多的子类
5)没有更多的手工工作
6)没有#imports
这是一个直接放在键盘上方的自定义控件。 我认为可以使用UIToolbar。
上一个和下一个遍历textFields的第一个响应者,Done将执行resign并隐藏工具栏。
要匹配键盘动画,请查看我找到的代码或SO: “iPhone的默认键盘动画速率是多少?”
我创建了一个存储库,其中包含此功能的实现,可在所有方向的iPhone / iPad上运行,并且可高度自定义。
正如其他答案所述,它是您正在寻找的inputAccessoryView
。
我想通过使用这个cocoapods在这里添加另一种方法:
所有UITextField
都有两个附加属性: nextTextField
和previousTextField
。 然后,您可以简单地在Interface Builder中连接nextTextField
,并自动为您添加Previous,Next和Done按钮,所有功能,不再需要代码,不进行子类化。
您还可以根据需要自定义UI,添加更多按钮等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.