Add a Decimal to UITextField : Number Pad Keyboard

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 the newest version of Cardio Track.

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: My Custom Number Pad Example Project

If you have questions about the additions that I made, feel free to email me.  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. brygruver@gmail.com

The Project Builds and Runs perfectly, but if I made any atrocious mistakes please feel free to correct me.

UITextField, KeyboardType:Number Pad, with Added Decimal

UITextField, KeyboardType:Number Pad, with Added Decimal

 

3 Comments

  1. [...] — Apple, in all of its infinite wisdom, decided to omit the dot for decimals. Following this guide, I was able to achieve this [...]

  2. Thanks, this project was really useful.

    I’m having trouble modifying the example to only show the keyboard for one particular UITextField – I posted a question about it on Stackoverflow (and cross referenced this site):
    http://stackoverflow.com/questions/1604327/how-to-find-out-what-uitextfield-caused-a-uikeyboardwillshownotification

  3. Bryan Gruver

    There is a new version of this project on my new site, http://www.cocoalines.com.

    Here is the direct link. It uses multiple Text Fields. http://brygruver.squarespace.com/customnumberpad/

Leave a comment

You must be logged in to post a comment.