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: firstname.lastname@example.org. 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.
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.)