I am trying to make an iphone application that displays mainly Arabic language content. I want to use a custom Arabic font for displaying that content, not the iPhone default Arabic font. I used the following code:
- (void)viewDidLoad {
[super viewDidLoad];
[arabicLabel setFont: [UIFont fontWithName: @"Simple Indust Shaded" size: 20]];
arabicLabel.text = @"السلام عليكم";
}
where arabicLabel is an IBOutlet UILabel. I put the label in the App resources and add it to the info.plist file as UIAppFont array item. Also the font is Unicode.
When I run this code on the simulator, the label displayed the default Arabic font (not my custom font); however it set its size to 20 as开发者_运维问答 stated in the code!
I don't understand what I did wrong here... I know that in the info.plist file I must add the font file name with extension (ttf), and I did that. Also, I know that in the previous code I had to put the actual font name not file name, so I opened the file in my Mac and used the title that appeared when the file is opened (Simple Indust Shaded).
Am I missing something? Are there any extra requirements for custom fonts other than being Unicode?
NB: I did the same procedure for custom English font, and it worked!...
Short answer
This seems to be a bug in iOS.
Long answer
As you may know, the arabic text needs to be shaped before it can be rendered, that means converting the basic letters (Unicode:0600-06FF) to their proper corresponding contextual letters (Unicode:FE70-FEFF).
iOS does this preprocessing automatically for arabic text, but for some reason, it forgets about the custom font and just uses system default font when it renders the connected letters.
So, it's a bug in iOS and you should wait for it to be solved.
Workaround
Though, if you can't wait, you can use this workaround: Do the preprocessing of the text manually before rendering it. This will allow skipping iOS preprocessing phase which causes this issue and thus rendering the text using your custom font.
If you want to test this solution, just copy this following line and try it in your project:
arabicLabel.text = @"ﺍﻟﺴﻼﻡ ﻋﻠﻴﻜﻢ";
THIS ANSWER IS FOR BELOW IOS 7.
I have also gone through this situation u can create your own hash map method for the replacement of 0600-06ff char with ur custom font but for that u need to check if your glyph in the TTF is mapped against 0600-06FF than u need to modify ur glyph mapped unicode except from 0600-06ff
for example if i made a TTF and mapped 'و' with unicode 0627 and when i try to see the effect of typed unicode 0627 char i.e(when i type 'ا' it must show 'و') it will not apply my custom image against it because ios6 will not allow u to change the glyph on the particular range . but if i would have mapped this custom char with Fxxx series or other than of 0600-06ff it will easily allow me to made custom change
Arabic(0600—06FF, 255 characters) u cannot play on this range or change the image of these glyph image with your custom image so mapped your glyph against the below arabic unicode Arabic Supplement (0750—077F, 48 characters) Arabic Extended-A (08A0—08FF, 39 characters) Arabic Presentation Forms-A (FB50—FDFF, 608 characters) Arabic Presentation Forms-B (FE70—FEFF, 140 characters)
here is the link for the similar type of thing done using custom arabic class and i also took help from it arabic custom font class
精彩评论