Possible Duplicate:
Struggling with currency in Cocoa Re-Apply currency formatting to a UITextField on a change event
I have been all over the web and either examples are no longer valid or people didn't really know what they were doing. So i have come to you guys for help,
I need to get a a textbox(TextField) to Display when they click into it a "$"...that was Easy lol
but i also need from the dollar sign to $0.00 then $0.01, $0.10 and so on.
And save an instance of it without the Symbols.
I am very new to Objective C and would like maybe a simple explanation or even a开发者_如何学Python good blog to read about it. "only if you just recently read it and its not outdated"
You want to use NSNumberFormatter
to accomplish this. The NSNumberFormatter documention from Apple is very good (I've just re-read it and it's not outdated). Specifically, look at the section on Configuring the Format of Currency. This should be enough to get you started.
Another good place to look if you prefer examples to documentation, is to read through the section on Number Formatters from Apple's Data Formatting Guide. This goes through examples of how to set up currency formatters to your specifications with concrete examples.
Finally, in order to integrate this with a UITextField
, you will want to use the delegate method
– textField:shouldChangeCharactersInRange:replacementString:
This allows you to validate and update characters as the user types them in.
精彩评论