James James - 4 months ago 34
Objective-C Question

How To Add Decimal To Number Pad - iOS

All,

How would I create a number pad with a decimal option in interface builder? The number pad that is provided doesn't show a decimal option.

Thanks

Answer

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.