[英]Is it possible to add done button inside the keyboard in iphone?
目前我正在使用iPhone应用程序,使用UITextField输入电话号码,用户输入电话号码,然后如何隐藏键盘? 因为这里没有返回按钮,是否可以在键盘内添加完成按钮,请帮帮我
提前致谢
这是一个很好的教程。
阅读此链接并尝试在您的应用程序中编码....
http://iphone-rahulvarma.blogspot.in/2012/03/numericpad-with-done-button.html
您可以使用“应用”和“取消”按钮添加inputAccessoryView,然后关闭数字键盘。
inputAccessoryView
- (void)viewDidLoad
{
[super viewDidLoad];
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[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)],
nil];
[numberToolbar sizeToFit];
numberTextField.inputAccessoryView = numberToolbar;
}
-(void)cancelNumberPad{
[numberTextField resignFirstResponder];
numberTextField.text = @"";
}
-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = numberTextField.text;
[numberTextField resignFirstResponder];
}
如果不使用完成按钮,您也可以通过触摸视图上的任何位置来隐藏数字键盘
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[yourtextfieldname resignFirstResponder];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.