xcode 如何以编程方式设置 iPhone 键盘以显示所需的键集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6021547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:02:40  来源:igfitidea点击:

How to programmatically set iphone keyboard to show desired key set

iosiphonexcodeuikeyboardtypeiphone-keypad

提问by Mike Hoover

I am programming an iPhone app that I want a text field where the user can add numbers from the keyboard and add them on the fly, ie, the user might type "1.5+2.4+6.3+.063" and as the user types additional numbers and plus signs the total is displayed immediately.

我正在编写一个 iPhone 应用程序,我想要一个文本字段,用户可以在其中从键盘添加数字并即时添加它们,即,用户可能会输入“1.5+2.4+6.3+.063”,并且当用户输入其他内容时数字和加号立即显示总数。

The problem is starting on and keeping the keyboard in the 123mode after the user types a + sign (using email keyboard because it has the numbers and the plus sign on the same view).

问题是123在用户键入 + 号后开始并保持键盘处于该模式(使用电子邮件键盘,因为它在同一视图上具有数字和加号)。

How can I start the email keyboard on the _123 screen and keep it there?

如何在 _123 屏幕上启动电子邮件键盘并将其保留在那里?

Thanks! Mike

谢谢!麦克风

回答by Jhaliya

use below code to set the keyboard type

使用下面的代码来设置键盘类型

myTextField.keyboardType = UIKeyboardTypeNumberPad;

All the keyboard type is define in UITextInputTraitsprotocol, which is implemented by UITextField

所有的键盘类型都在UITextInputTraits协议中定义,协议由UITextField实现

回答by Sid

Depending on what textfield you want to set it for you go:

根据您要为您设置的文本字段:

[textField setKeyboardType:(UIKeyboardType)];

Where UIKeyboardType could be any of the following: UIKeyboardTypes

其中 UIKeyboardType 可以是以下任何一种:UIKeyboardTypes

***EDIT

***编辑

In your case you would do:

在你的情况下,你会这样做:

[textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];

***EDIT

***编辑

回答by AamirR

No, I could not find a way to programmatically change keyboard modes to 123or #+=.

不,我找不到以编程方式将键盘模式更改为123或 的方法#+=

But if you want the default keyboard start as if user had pressed the 123button on keypad, your only choice is:

但是,如果您希望默认键盘启动就像用户按下了123键盘上的按钮一样,您唯一的选择是:

textField.keyboardType = UIKeyboardType.numbersAndPunctuation

Here is how numbersAndPunctuationkeypad will be presented

以下是numbersAndPunctuation键盘的显示方式

enter image description here

在此处输入图片说明

Other related/useful keypad types are:

其他相关/有用的键盘类型是:

textField.keyboardType =.numberPad

enter image description here

在此处输入图片说明

textField.keyboardType =.decimalPad

enter image description here

在此处输入图片说明

textField.keyboardType =.phonePad

enter image description here

在此处输入图片说明