ios 文本字段键盘设置为数字键盘,但选择时显示常规键盘

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22348395/
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-08-30 23:42:35  来源:igfitidea点击:

Text Field keyboard set to Number Pad but regular keyboard is displaying on selection

iosxcodeipadxamarin

提问by 5uperdan

I have set my text field's keyboard to 'Number Pad' in the xcode designer which adds the following code between my tags in my .xib

我在 xcode 设计器中将我的文本字段的键盘设置为“数字键盘”,它在我的 .xib 中的标签之间添加了以下代码

<textInputTraits key="textInputTraits"
autocorrectionType="no" keyboardType="numberPad"/>

I had expected that when selecting this textfield, the following keyboard input would appear:

我原以为在选择此文本字段时,会出现以下键盘输入:

enter image description here

在此处输入图片说明

But instead, the following input is appearing:

但相反,出现了以下输入:

enter image description here

在此处输入图片说明

How can i set my text field to use the first input (or similar) instead of the second?

如何将文本字段设置为使用第一个输入(或类似输入)而不是第二个?

回答by Daan Olislagers

You could use yourTextField.KeyboardType = UIKeyboardTypePhonePadif you are on a iPhone. iPad's do not support this type of keyboard. An iPad will display the NumberPad.

yourTextField.KeyboardType = UIKeyboardTypePhonePad如果您使用的是 iPhone,则可以使用。iPad 不支持这种类型的键盘。iPad 将显示数字键盘。

回答by Sujith Thankachan

You can set keyboardTypeproperty of UITextFiledto UIKeyboardTypePhonePadas follows:

您可以按如下方式设置to 的keyboardType属性:UITextFiledUIKeyboardTypePhonePad

yourTextField.KeyboardType = UIKeyboardType.NumberPad

回答by Andy

If you are on iOS 7 use following code :

如果您使用的是 iOS 7,请使用以下代码:

self.valueField.keyboardType = UIKeyboardTypeNumberPad;

回答by zeeshan

As of Swift 3, it is now a little different. For a UITextField, e.g. height, it'll be like this:

Swift 3 开始,它现在有点不同。对于 UITextField,例如高度,它将是这样的:

@IBOutlet weak var height: UITextField!

height.keyboardType = UIKeyboardType.numbersAndPunctuation

OR

或者

height.keyboardType = UIKeyboardType.numberPad

Now when you press the text field, proper keyboard will popup.

现在,当您按下文本字段时,将弹出正确的键盘。

回答by Khushboo Dhote

Swift 3

斯威夫特 3

In viewDidLoad write -

在 viewDidLoad 中写入 -

    mobileTextfield.keyboardType = UIKeyboardType.numberPad

you can get more choices in UIKeyboardType

你可以得到更多的选择 UIKeyboardType