JDFCurrencyTextField

Easier Currency Entry

Working with monetary values is a pretty integral part of Live Poker Manager. Whilst developing the app, I needed to come up with an easy, intuitive way to allow the user to enter monetary values. Obviously, a plain old UITextField wasn’t going to cut it.

So, I created JDFCurrencyTextField. It’s a simple UITextField subclass that made entering monetary values easy for the user.

Its easy for the developer as well. Simply use it in place of a UITextField. You can set the initial value as an NSDecimalNumber via the decimalValue property. The value will be formatted as a monetary value for display (using the device’s default locale by default, but this can be changed by setting the currency text field’s locale property).

To get the value back out of it, again use the decimalValue property.

A quick example:

1
2
3
4
JDFCurrencyTextField *currencyField = [[JDFCurrencyTextField alloc] initWithFrame:frame];
currencyField.decimalValue = [[NSDecimalNumber alloc] initWithDouble:9.99];
[myView addSubview:currencyField];
// The text field shows '£9.99'



User Experience

Lets take a look at some typical usage. Create a JDFCurrencyTextField and set its value to 9.99.

It gets formatted nicely. Cool. When the user starts editing, it becomes a plain number again:

The user changes the value:

When the user finishes editing, and it gets formatted nicely again (complete with decimal places).

Start editing again, and as there are only zeros after the decimal point, they dissapear.

So there it is. Pretty simple, but a nice little touch that makes things a bit nicer for the user. Check it out on GitHub (it’s also available as a CocoaPod). I’d love to hear if you’re using it in any of your apps.