テキスト フィールドに通貨を設定して、先頭に 0 を付けてローカライズされた通貨として表示するにはどうすればよいでしょうか。誰かが 16.25 ペンスを入力すると、それぞれ 0.1625 ポンドとしてフォーマットされます。委任を使用し、すべてのテキスト フィールドをフォーマットして、数値のみを渡すことができるようにしています。このフィールドもローカライズする必要があります。
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { // First, create the text that will end up in the input field if you'll return YES:
NSString *resultString = [textField.text stringByReplacingCharactersInRange:range withString:string];
// Now, validate the text and return NO if you don't like what it'll contain.
// You accomplish this by trying to convert it to a number and see if that worked.
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber* resultingNumber = [numberFormatter numberFromString:resultString];
//[numberFormatter release];
return resultingNumber != nil;
すべてのフィールドがフォーマットされるため、これを変更したくありません。textField1 に適切な形式を持たせたいだけですが、これを行うにはどうすればよいですか? それは viewdidload メソッドにあり、テキスト プロパティを浮動小数点にローカライズするように設定していると思いますが、その方法がわかりません。