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:
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:
- Select the Textfield in Interface Builder
- Edit
Keyboard Type
in xib or Storyboard - Select
Decimal 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.
精彩评论