我正在使用一个包含本地化货币值的UITextField.我已经看过很多关于如何使用它的帖子,但我的问题是:如何在每次按键后将货币格式重新应用到UITextField?
我知道我可以设置和使用货币格式化程序:
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
...
[currencyFormatter stringFromNumber:...];
Run Code Online (Sandbox Code Playgroud)
但我不知道如何勾选它.
例如,如果字段中的值显示为"$ 12,345"并且用户点击"6"键,则该值应更改为"$ 123,456".
哪个回调是执行此操作的"正确"(我应该使用textField:shouldChangeCharactersInRange:replacementString:或自定义目标操作),如何使用NSNumberFormatter解析并重新应用格式到UITextField的文本属性?
任何帮助将非常感激!谢谢!