Setting the font for the languages other than english
I am doing a Fo开发者_StackOverflownt application for the Mac. I got all the font names from the location "/Library/Fonts/"
and saved them in an array named FontArray
. I just have to preview all the fonts in a NSTextView. This is my code for the NSTextView:
NSTextView *textView=[[NSTextView alloc]initWithFrame:NSMakeRect(250,500,450,30)];
[textView setString:@"ABCDEFGHIJKLMMOPQRSTUVWXYZ"];
[textView setFont:[NSFont fontWithName:[FontArray objectAtindex:rowid] size:40]];
This function will be called when a tableview row has been clicked. This works correctly for all the english fonts. But whenever non english fonts clicked means it gives an error like *** -[NSTextView setFont:]: nil NSFont given.
How can I change my code to correct this error.
You're on a completely wrong road. A font is not a font file; the name of the font contained inside a font file is not necessarily the same as the name of the file, as you've discovered. Instead of trying to work with the font files directly, use NSFontManager
.
精彩评论