如何以编程方式使用键盘上的下一个和上一个工具栏在可编辑字段之间导航?

时间:2013-04-19 15:36:09

标签: iphone

如何以编程方式使用键盘上的下一个和上一个工具栏在可编辑字段(Textfield,Textarea,Datepicker,Pikerview)之间导航?

2 个答案:

答案 0 :(得分:0)

https://github.com/simonbs/BSKeyboardControls

此控件可以在编辑像这样的文本字段时显示键盘上方的工具栏

enter image description here

答案 1 :(得分:0)

UIBarButtonItem *prevButton = [[UIBarButtonItem alloc] initWithTitle:@"Prev" style:UIBarButtonItemStyleBordered target:self action:@selector(prevButtonPressed:)];    
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextButtonPressed:)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)]

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolbar.barStyle = UIBarStyleBlackTranslucent;
[toolbar setItems:@[prevButton, nextButton, flexibleSpace, doneButton]];

UITextView *textView = [[UITextView alloc] inithWithFrame:CGRectMake(x, y, width, height)];
textView.inputAccessoryView = toolbar;

您可以使用UISegmentedControl创建类似于@adali发布的上一个/下一个效果