All Projects → marzapower → MPNumericTextField

marzapower / MPNumericTextField

Licence: MIT license
A class that extends UITextField to input numbers, percentages and currencies.

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to MPNumericTextField

Countries
Countries, Languages & Continents data (capital and currency, native name, calling codes).
Stars: ✭ 656 (+3544.44%)
Mutual labels:  currencies
Javamoney Lib
JavaMoney financial libraries, extending and complementing JSR 354
Stars: ✭ 104 (+477.78%)
Mutual labels:  currencies
Fixer
A foreign exchange rates and currency conversion API
Stars: ✭ 2,545 (+14038.89%)
Mutual labels:  currencies
Money bot
Docker-containered bot. Added to a group chat, she replies to any message containing price and currency pattern. Live!
Stars: ✭ 8 (-55.56%)
Mutual labels:  currencies
Oxr
💱 Node.js wrapper for the Open Exchange Rates API
Stars: ✭ 72 (+300%)
Mutual labels:  currencies
Node Currency Swap
Currency Exchange Rates library for nodejs
Stars: ✭ 119 (+561.11%)
Mutual labels:  currencies
Financedatabase
This is a database of 180.000+ symbols containing Equities, ETFs, Funds, Indices, Futures, Options, Currencies, Cryptocurrencies and Money Markets.
Stars: ✭ 554 (+2977.78%)
Mutual labels:  currencies
BitBlocks old
BitBlocks Project_OLD
Stars: ✭ 12 (-33.33%)
Mutual labels:  currencies
Countries
Countries - ISO 3166 (ISO3166-1, ISO3166, Digit, Alpha-2 and Alpha-3) countries codes and names (on eng and rus), ISO 4217 currency designators, ITU-T E.164 IDD calling phone codes, countries capitals, UN M.49 regions codes, ccTLD countries domains, IOC/NOC and FIFA letters codes, VERY FAST, NO maps[], NO slices[], NO init() funcs, NO external links/files/data, NO interface{}, NO specific dependencies, Databases/JSON/GOB/XML/CSV compatible, Emoji countries flags and currencies support, full support ISO-3166-1, ISO-4217, ITU-T E.164, Unicode CLDR and ccTLD standarts.
Stars: ✭ 85 (+372.22%)
Mutual labels:  currencies
Cash Cli
💰💰 Convert currency rates directly from your terminal!
Stars: ✭ 168 (+833.33%)
Mutual labels:  currencies
Livecoin Api
LiveCoin RESTful API wrapper for Node.js
Stars: ✭ 12 (-33.33%)
Mutual labels:  currencies
Cldr
Internationalize your application using Unicode's CLDR
Stars: ✭ 38 (+111.11%)
Mutual labels:  currencies
Django Prices
Django fields for the prices module
Stars: ✭ 135 (+650%)
Mutual labels:  currencies
Gocurrency
Simple currency converter. Insert an amount, what currency to convert from and what currency to convert to.
Stars: ✭ 26 (+44.44%)
Mutual labels:  currencies
Prices
Python price handling for humans.
Stars: ✭ 248 (+1277.78%)
Mutual labels:  currencies
Alfred Convert
Convert between different units in Alfred
Stars: ✭ 560 (+3011.11%)
Mutual labels:  currencies
Currency
Handles currency calculations, storage etc
Stars: ✭ 109 (+505.56%)
Mutual labels:  currencies
latinum
Latinum is a framework for resource and currency calculations.
Stars: ✭ 109 (+505.56%)
Mutual labels:  currencies
hdx-python-country
Utilities to map between country and region codes and names and to match administrative level names from different sources. Also utilities for foreign exchange enabling obtaining current and historic FX rates for different currencies
Stars: ✭ 16 (-11.11%)
Mutual labels:  currencies
Nodamoney
NodaMoney provides a library that treats Money as a first class citizen and handles all the ugly bits like currencies and formatting.
Stars: ✭ 144 (+700%)
Mutual labels:  currencies

MPNumericTextField

MPNumericTextField is a class that extends the basic UITextField to make you easily input formatted numbers in a text field.

It correctly handles decimal numbers, integer numbers, percentages and currency values, using either the current locale or a manually provided one.

Screenshot of BasicExample

Installation

Using CocoaPods (preferred one!)

Just add the following line to the Podfile in your project:

pod "MPNumericTextField", '~> 1.4.0'

Manually

Just add to your project these main files:

  1. MPNumericTextField.h
  2. MPNumericTextField.m
  3. MPNumericTextFieldDelegate.h
  4. MPNumericTextFieldDelegate.m
  5. MPFormatterUtils.h
  6. MPFormatterUtils.m

that can be found inside the Classes folder.

Usage

You can create a very simple numeric text field using:

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

This will create a text field that will handle the input of decimal numbers, using the current locale and the local text field delegate implementation (see MPNumericTextFieldDelegate.{h|m}).

Decimal, percentage or currency?

You can change the default number style for the text field via the type property. It can be set to one of these values:

  1. MPNumericTextFieldDecimal (default one)
  2. MPNumericTextFieldInteger
  3. MPNumericTextFieldCurrency
  4. MPNumericTextFieldPercentage

Eg. to change the number style of your text field to currency just do:

numericTextField.type = MPNumericTextFieldCurrency;

Getting and setting the numeric value

You can access the numeric value of your text field via the numericValue property. Eg:

MPNumericTextField *textField = [[MPNumericTextField alloc] init];
textField.type = MPNumericTextFieldPercentage;
textField.numericValue = @(2.25);

// ... (make changes to the text field) ...

NSNumber *currentValue = textField.numericValue;

Locales

By default behavior the MPNumericTextField will use the [NSLocale currentLocale] locale. But you can easily change this property too:

numericTextField.locale = myCustomLocale;

Custom currencies

When using MPNumericTextField for displaying currencies, an old limitation was to be stuck with the currency code provided by NSLocale.

Starting from v. 1.3.0 it's possible to set a custom currency code to represent those values using the desired currency:

numericTextField.currencyCode = @"JPY";

Delegates

The MPNumericTextField class seamlessly uses the MPNumericTextFieldDelegate class as its own delegate. This delegate handles all the logics that makes the text field draw numbers with the correct format while the user inserts numbers.

You can decide to set a new custom delegate for your objects, and the MPNumericTextField will treat them as forward delegates to make them work correctly with the existing one.

Unlike version 1.0.0 of this library, starting from 1.1.0 you can start using the standard -setDelegate: and -delegate methods from UITextField to set up your custom delegates without worrying about the basic numeric field functionalities.

Bonus: placeholder color

You can choose to change the default placeholder color in your text field. Just use the placeholderColor property:

numericTextField.placeholderColor = [UIColor redColor];

If this property is set to nil, it will use the default system color.

Support

Feel free to apport changes to the source code of this project and to send a pull request on Github to merge your contribution to the original project.

If you need further assistance, please contact me on Twitter: @marzapower.

Release notes

Version 1.4.0

  • [new] The new MPTextField class opens the usage of placeholderColor outside of the handling of the numeric text field
  • [fix] No more default right alignement for the text field if loaded from a NIB file

Version 1.3.0

  • [new] Custom currency codes for the text field
  • [new] Nullability modifiers for the utility methods in MPFormatterUtils

Version 1.2.1

  • [fix] Doesn't use cached locale anymore when system locale changes

Version 1.2.0

  • [New] Added support to integer-only numbers with MPNumericTextFieldInteger
  • [Enh] Better support for Swift integration

Version 1.1.0

  • [Fix] Added support for all delegate methods in MPNumericTextFieldDelegate
  • [New] Added support for custom delegates without boilerplate code
  • [New] Added IB_DESIGNABLE keyword to MPNumericTextField
  • [Enh] Some little code enhancements

Version 1.0.0

  • First public release
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].