Writing Hindi language on UILabel in Xcode

纵然是瞬间 提交于 2019-12-05 07:56:55

问题


I have written a code where I need to display hindi numbers on the UILabel. I used devanagari font to show that value but it doesn't work. It just changes the look but not the language.

I was using:

UIFont *font = [UIFont fontWithName:@"DevanagariSangamMN" size:16];
myLabel.font = font;

But it's not working. Can anyone please help me with this?


回答1:


You have got the font name wrong. The font name is DevanagariSangamMN not DevanagarSangamMN (note the missing 'i' in your name). Your code should therefore be:

UIFont *font = [UIFont fontWithName:@"DevanagariSangamMN" size:16]; 
myLabel.font = font;

To find more information about the iOS Fonts. I recommend this website which has all the fonts available in iOS

Also, if you type English characters into the Label, you will get returned the English version NOT the Hindi translation. It doesn't do the translation for you. Using the DevanagariSangamMN only allows you to show the Hindi Characters because the fonts such as Helvetica which are normally used do not include the Hindi glyphs. For example:

UIFont *font = [UIFont fontWithName:@"DevanagariSangamMN" size:16]; 
myLabel.font = font;
myLabel.text = @"Testing";

This will return 'Testing' in English, Not in Hindi. However if you do:

UIFont *font = [UIFont fontWithName:@"DevanagariSangamMN" size:16]; 
myLabel.font = font;
myLabel.text = @"परीक्षण";

Then you will get 'परीक्षण' which is the Hindi for 'Testing' (I used Google Translate so it could be wrong). So to get the number '4' with the Hindi version (४), you need to do the following:

UIFont *font = [UIFont fontWithName:@"DevanagariSangamMN" size:16]; 
myLabel.font = font;
myLabel.text = @"४";



回答2:


are you assigning your UILabel text in unicode? Try this -

myLabel.text = [NSString stringWithFormat:@"String with unicode %C", 0x207F];


来源:https://stackoverflow.com/questions/7513928/writing-hindi-language-on-uilabel-in-xcode

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