开发者

How to add Decimal Separator character to iOS keyboard Number Pad?

How can I create a number pad with a de开发者_如何学运维cimal point separator character option in Xcode's Interface Builder Storyboard?

Changing Keyboard Type to Number Pad doesn't show a decimal option:

How to add Decimal Separator character to iOS keyboard Number Pad?

How to add Decimal Separator character to iOS keyboard Number Pad?


In iOS 4.1, there is a number pad with a decimal point available. You can select it programatically (in case you are supporting versions of iOS before 4.1) like so:

inputBoxTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
if (([[[UIDevice currentDevice] systemVersion] doubleValue] >= 4.1)) {
    inputBoxTextField.keyboardType = UIKeyboardTypeDecimalPad;
}

You could choose any appropriate keyboard type (line 1). In this case, NumbersAndPunctuation includes a period in case the user's iOS version is before 4.1.


In Swift:

priceText.keyboardType = .decimalPad


In iOS 8 or above follow these steps:

  1. Select the Textfield in Interface Builder
  2. Edit Keyboard Type in xib or Storyboard
  3. Select Decimal Pad

How to add Decimal Separator character to iOS keyboard Number Pad?

How to add Decimal Separator character to iOS keyboard Number Pad?


I have developed an open source custom decimal keyboard. Methods and implementations are very easy to use and you can change buttons or add/remove extra buttons as you see fit. Please have at look at the repository here TD-DecimalKeyboard and feel free to fork and contribute.

How to add Decimal Separator character to iOS keyboard Number Pad?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜