Skip to content

Latest commit

 

History

History
43 lines (40 loc) · 1.2 KB

README.md

File metadata and controls

43 lines (40 loc) · 1.2 KB

MSCurrencyFormatter

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!