Skip to content

thiagorossener/TRCurrencyTextField

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TRCurrencyTextField

Build Status Version License Platform

What it is?

TRCurrencyTextField is a component to make currency formatted input easy to get. It provides a real-time currency formatted text while the user types on number pad.

TRCurrencyTextField Example

What it does?

  • No value means value 0
  • Digits come from right to the left
  • No need to type commmas or dots
  • Delete shifts digits
  • Edit text from the middle
  • Paste from anywhere
  • Change currency code easily
  • Change country code easily
  • Change locale easily
  • Set maximum of digits
  • Whitespace close to symbol configurable
  • Get text value (ex: R$ 1.234,00)
  • Get number value (ex: 1234.0)

More details here.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

TRCurrencyTextField is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "TRCurrencyTextField"

How to create a TRCurrencyTextField

The component is always created with:

  • Currency code: BRL
  • Value: 0
  • Max digits: 11
  • Whitespace close to symbol: true

To create a component, just do what you are used to do:

TRCurrencyTextField *textField = [[TRCurrencyTextField alloc] init];

Change the Value

From R$ 0,00 to R$ 1.234,00, you can do for example:

textField.value = [NSNumber numberWithInt:1234];

Change the Currency Code

From R$ 1.234,00 to $ 1,234.00

textField.currencyCode = @"USD";

Change the Country Code

From $ 1,234.00 to 1 234,00 €

[textField setCountryCode:@"FR"];

It is possible only with set method, because one country has only one currency, but one currency can be used on many countries.

So, you can set only one country, but you can get all of countries which use the currency.

Change the Locale

From 1 234,00 € to US$ 1,234.00

[textField setLocale:@"en_ZW"];

Also, it is possible only with set method.

Change max digits

You can set the maximum of number digits on the text, so to change, for example, from US$ 999,999,999.99 to US$ 999,999.99

textField.maxDigits = 8;

Hide the whitespace close to symbol

Also, you can remove the whitespace close to symbol.

So, from US$ 1,234.00 to US$1,234.00

textField.addWhiteSpaceOnSymbol = NO;

Release Notes

Version 0.1.1

  • Fixed crashes caused by editing currency symbol
  • Fixed conversion from value to string in TRFormatterHelper
  • Added support for Editing Changed event

Version 0.1.0

  • Initial release

Author

Thiago Rossener

License

TRCurrencyTextField is available under the MIT license. See the LICENSE file for more info.

About

iOS text field to input formatted currency value.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 80.9%
  • Shell 17.7%
  • Ruby 1.4%