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.
- 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.
To run the example project, clone the repo, and run pod install
from the Example directory first.
TRCurrencyTextField is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "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];
From R$ 0,00 to R$ 1.234,00, you can do for example:
textField.value = [NSNumber numberWithInt:1234];
From R$ 1.234,00 to $ 1,234.00
textField.currencyCode = @"USD";
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.
From 1 234,00 € to US$ 1,234.00
[textField setLocale:@"en_ZW"];
Also, it is possible only with set method.
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;
Also, you can remove the whitespace close to symbol.
So, from US$ 1,234.00 to US$1,234.00
textField.addWhiteSpaceOnSymbol = NO;
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
TRCurrencyTextField is available under the MIT license. See the LICENSE file for more info.