iPhone 动态更改基于县的货币符号?
我想根据用户的本地化更改 iPhone 应用程序中的货币符号。如果我的应用程序在美国运行,我需要更改货币符号“$”。如果应用程序在欧洲国家运行,我们需要将符号更改为“€”,如果应用程序在日本运行,则符号应更改为“日元”,如果应用程序在澳大利亚运行,则符号应为“ $”。通过这种方式,如果应用程序在任何国家/地区运行,则应用程序应该根据本地化更改货币符号。我使用了下面的代码,但是它总是显示在“$”中。我该如何解决这个问题?我该如何测试这个?请帮我。
NSNumberFormatter *currencyFormat = [[NSNumberFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
[currencyFormat setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormat setLocale:locale];
NSLog(@"Amount with symbol: %@", [currencyFormat stringFromNumber:@"10.00"]);
请帮我。我哪里错了?提前致谢。
I want to change the currency symbols in iPhone app based on user's localization. If my app is working in US i need to change the currency symbol "$". If the app is working in Eroupe countries, we need to change the symbol to "€", if the app is in Japan, the symbol should be change to "¥" and if the app is running in Australia the symbol should be in "$". By this way if the app is running in any country the app should be change the currency sign based on the localizations. I have used this below code but, it always shows in "$". How can i solve this? And also how can i test this? Please help me.
NSNumberFormatter *currencyFormat = [[NSNumberFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
[currencyFormat setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormat setLocale:locale];
NSLog(@"Amount with symbol: %@", [currencyFormat stringFromNumber:@"10.00"]);
Please help me. Where i am wrong? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模拟器支持更改本地化,就像在常规设备上一样。确保在启动应用程序之前进行更改,并且它应该显示正确的格式。
要更改区域设置(在模拟器上):
启动模拟器(通过启动您的应用),按
Home
按钮,转到Settings
、General
、International
然后选择您要测试的区域格式
。完成后关闭模拟器并重新启动您的应用程序。区域设置已更改,因此您应该在显示的货币符号中看到这一点。在真实设备上,您可以按照相同的路线更改区域设置。
The simulator has support for changing localizations, just like on a regular device. Make sure that you change that before starting your app and it should show the correct format.
To change the locale (on the simulator):
Start the simulator (by starting your app), press the
Home
button, go toSettings
,General
,International
and then choose theRegion Format
you want to test. Close the simulator after it's done and restart your app. The locale has changed so you should see that in the currency symbol that is shown.On real devices you follow the same route to change the locale.