如何显示“完成"iOS数字键盘上的按钮? [英] How to show "Done" button on iOS number pad keyboard?
本文介绍了如何显示“完成"iOS数字键盘上的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
没有完成".numberPad
键盘类型上的按钮.当用户在文本字段中输入完数字信息后,如何让数字键盘消失?
There is no "Done" button on the .numberPad
Keyboard Type. When a user finishes entering numeric information in a text field, how can I make the number pad disappear?
我可以得到一个完成"按钮使用默认键盘,但用户必须切换到数字键才能输入数字.有没有办法显示完成"?数字键盘上的按钮?
I could get a "Done" button by using the default keyboard, but then users would have to switch to the numeric keys in order to input numbers. Is there a way to show a "Done" button on the number pad?
推荐答案
另一种解决方案.如果屏幕上还有其他非数字键盘文本字段,那就完美了.
- (void)viewDidLoad
{
[super viewDidLoad];
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = @[[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)]];
[numberToolbar sizeToFit];
numberTextField.inputAccessoryView = numberToolbar;
}
-(void)cancelNumberPad{
[numberTextField resignFirstResponder];
numberTextField.text = @"";
}
-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = numberTextField.text;
[numberTextField resignFirstResponder];
}
这篇关于如何显示“完成"iOS数字键盘上的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文