Change currency symbol based on county dynamically iPhone?

被刻印的时光 ゝ 提交于 2019-12-08 04:40:42

问题


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.


回答1:


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 to Settings, General, International and then choose the Region 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.



来源:https://stackoverflow.com/questions/8557467/change-currency-symbol-based-on-county-dynamically-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!