MSCurrencyFormatter 0.0.4

MSCurrencyFormatter 0.0.4

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.



  • By
  • Brandon Butler and Olexandr Skrypnyk

A piece of code that will automatically format a uitextfield with a numberpad to behave like an ATM

Here's an example

Create a property for the formatter

@property (nonatomic, retain) MSCurrencyFormatter *priceFormatter;

In the viewDidLoad make sure to initalize

self.priceFormatter = [[MSCurrencyFormatter alloc] init];

Wherever you setup your textfield set the priceFormatter as the delegate

myTextField.delegate = self.priceFormatter;

To automatically add the "+/-" button to the numberpad (iphone only) call this method.

[self.priceFormatter startWatchingForKeyboardFromTextField:myTextField];

(optional) if you want to handle the delegation yourself you can do this also.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

 textField.text = [MSCurrencyFormatter formatTextField:textField withReplacementString:string]
 return NO;
}

If you have a textfield in a UIAlertView be sure to call "startWatchingFor..." everytime you show the alert.

You're done!