Creating a Custom Number Pad
Thursday, October 1, 2009 at 04:12PM As of iOS SDK 4.1 all you need to do is the following: textField.keyboardType = UIKeyboardTypeDecimalPad;
Strangely, the option does not appear to be available in Interface Builder, you must set in code. I suggest either in awakeFromNib, viewDidLoad or viewWillAppear.
So Apple, in all of their infinite wisdom, offers a number pad for the keyboard of a UITextField but it has no decimal. With a lot of work and research I was able to finally pull off adding a decimal and it is included in Cardio Track and OnTrac Fit.
Click to View (You must register to View.): The original article that I used as a reference.
Included in the article is an example project file that includes all of the code in a working project. It does work, but I found it lacking. I had to modify it pretty heavily to get it to work in my App. So I created a new sample project that includes all of the additions that I made to get it to work properly in my App. (Plus I simplified it by adapting it use Interface Builder.) I had to do these additions because my Editing Page was several View Controllers in, and I use other keyboards throughout my app other than the number pad.
My first addition allows the AppDelegate to worry about the keyboard, while using the notification center (NSNotificationCenter) to send a message to append the decimal.
My second addition includes an App wide BOOL value that conditionally enables decimal button. I did this because I use different keyboards throughout the app and sometimes I don’t want or need the decimal.
Click to download: Custom Number Pad Example
If you have questions about the additions that I made, feel free to email me: cocoalines@gmail.com. You may also email me if you have questions about the rest of the code in the project. I will try my best to explain it, but some of it I don’t even understand. It is heavily commented and the original article has a pretty good explanation of it as well.
The Project Builds and Runs perfectly, but if I made any atrocious mistakes please feel free to correct me.
Bryan S. Gruver
I've added some code to make this method compatible with iPhone Apps running on the iPad Simulator beta 5. I also changed the code around slightly to make it cleaner and better memory management of the dot itself.
The dot also now plays the keyboard click sound on iPhone Hardware. It does not observe whether or not users have keyboard sound effects turned off. Not quite sure how to do that.
I also included the images for the transparent dot if you're using the Alert Style Keyboard.
Thanks to my friend Simon for making me aware of the changes in the iPad SDK.
If you are writing an actual iPad application, you should not use this method for modifying the keyboard. The iPad sdk includes hooks to allow you to create custom keyboards and add to existing.
Check out the "Replacing the System Input Views" section of the UITextField Documentation. Or search for the properties, "inputView" and "inputAccessoryView". (Only available on iPhone OS 3.2 and later.)

Reader Comments (6)
Hi, I have five total field inputs. The first three will use the standard num pad, but the last two will use your code. How can I modify your code to allow for the last two to show the dot and use it correctly? I am trying to use the dot within a double float integer. Any help would be greatly appreciated!
Thanks for the example code, exactly what I was looking for!
It looks like these custom keyboard modifications do not work with devices running iPhone OS4 (beta). I guess that means we have only a few weeks to update our apps, otherwise they will be broken when OS4 is released to the public. Any ideas?
Useful post, thanks. One thing is that using this view seems to override any background settings (color/image) that I have in IB.
Hello Bryan,
Thank you for the article and sample code!
Numeric keyboards with decimals added to them are causing problems for those of us trying to prepare our apps for next week. Was wondering if you've had any luck making your solution work in OS4.
Sarah
Thanks a lot of for your post it's helful