最も簡単な方法は、右揃えのテキストをテキストフィールドに重ねて配置することです(テキストが配置されたままになります)。
- (void)textFieldDidBeginEditing:(UITextField *)textField {
self.currencyLabel.text = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencySymbol];
}
あなたがテキストフィールド内のテキストの一部としてそれを維持したい場合は、それはあなたがする必要があるとして、少し複雑になる:ユーザーがテキストフィールドを編集し始め
、通貨記号を設定しますあなたはそれをそこに置いたら、シンボルを削除するからそれらを保つ:
// Set the currency symbol if the text field is blank when we start to edit.
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField.text.length == 0)
{
textField.text = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencySymbol];
}
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:string];
// Make sure that the currency symbol is always at the beginning of the string:
if (![newText hasPrefix:[[NSLocale currentLocale] objectForKey:NSLocaleCurrencySymbol]])
{
return NO;
}
// Default:
return YES;
}
@Aadhiraが指摘するように、あなたがそれをユーザーに表示されているので、あなたも数フォーマッタを使用して通貨をフォーマットする必要があります。
あなたは「Xcodeのの通貨記号」とはどういう意味ですか? –