【问题标题】:iOS: Is it possible to have a return key on number pad?iOS:数字键盘上是否可以有返回键?
【发布时间】:2014-03-13 21:42:57
【问题描述】:

iOS 中的标准键盘确实有一个返回键,并且有一个委托方法,当用户点击返回键时会调用该方法。

数字键盘上可以有返回键吗?

【问题讨论】:

    标签: ios uitextfield


    【解决方案1】:

    你可以这样做,你可以设置你自己的工具栏位置。

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
    {
        if( textField == yourTextField )
        {
            UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
            numberToolbar.barStyle = UIBarStyleBlackTranslucent;
            numberToolbar.items = [NSArray arrayWithObjects:
                                   [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                                   [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                                   [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButton)],nil];
            textField.inputAccessoryView = numberToolbar;
    }
    }
    
    - (void)doneButton
    {
        [youtTextField resignFirstResponder];
    }
    

    【讨论】:

      【解决方案2】:

      没有办法修改标准数字键盘。典型的解决方案是设置一个带有按钮的工具栏,并将此视图设为文本字段的inputAccessoryView。然后在点击按钮时在文本字段上调用resignFirstResponder

      【讨论】:

      • @maddy 工具栏会显示在哪里?我一直在另一个项目中使用pickerview作为inputAccessoryView,并且显示的是pickerview而不是textview的键盘。但是我不需要带有按钮而不是键盘的工具栏,我需要同时显示。你试过吗?
      • 我认为您的意思是您一直使用UIPickerView 作为inputViewinputAccessoryView 显示在键盘顶部(或 inputView)。
      • 对,我的错,是inputView。我一直在查看我在互联网上找到的一些示例,它们包含大量代码,只是为了在数字键盘顶部显示一个返回键。你有一个简短示例的链接吗?
      • 不,我没有。只需创建一个工具栏,添加一个按钮,然后设置按钮处理程序以关闭键盘。将工具栏指定为文本字段的inputAccessoryView。没什么大不了的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-25
      • 2013-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-05
      • 2016-09-14
      相关资源
      最近更新 更多