-->

是否有可能加入键盘iphone内部完成按钮?(Is it possible to add done

2019-10-17 05:06发布

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

提前致谢

Answer 1:

这里是约一个很好的教程。



Answer 2:

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

不过,我会建议你使用inputAccessoryView代替。 请参阅本SO发布 。

而且必须读 这个苏答案 。



Answer 3:

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

http://iphone-rahulvarma.blogspot.in/2012/03/numericpad-with-done-button.html



Answer 4:

你可以用“应用”和“取消”按钮添加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];
}


Answer 5:

如果不使用完成按钮,您还可以通过在任何地方视图触摸这种方式隐藏数字键盘

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [yourtextfieldname resignFirstResponder];
}


文章来源: Is it possible to add done button inside the keyboard in iphone?