繁体   English   中英

是否可以在iPhone的键盘内添加完成按钮?

[英]Is it possible to add done button inside the keyboard in iphone?

目前我正在使用iPhone应用程序,使用UITextField输入电话号码,用户输入电话号码,然后如何隐藏键盘? 因为这里没有返回按钮,是否可以在键盘内添加完成按钮,请帮帮我

提前致谢

下面提到的图片供你参考,左边的空白区域添加完成按钮,有可能吗?

是一个很好的教程。

请参阅此链接。 它显示了如何在键盘中添加“完成”按钮。

但我建议你改用inputAccessoryView 请参阅此SO帖子

并且必须阅读 这个SO答案

阅读此链接并尝试在您的应用程序中编码....

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM