![](/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.