views:

297

answers:

3

Hi,

I have a file with Chinese text that I want to use in my xcode project (I'm planning to load it through a database as it is lot of text), the problem is I dont know how to add the font to my project so that its viewable when used on an iPhone?

Thanks :)

+1  A: 

The iPhone already has chinese fonts installed by default.

Williham Totland
Thanks for your quick reply, the one I'm planning on using is more of a stylised version, is there a way to add it ?
Dave
I do believe the iPhone comes with a Mincho and a Gothic variant (roughly serif/sans-serif). On the whole I'd recommend against mucking about with fonts; nothing good ever comes of it. If you absolutely must (tho' again, I'd recommend against it, this, I feel, needs to be said), you would place the font in your application bundle; this *might* enable UIFont to load it using fontWithName: and friends, tho' I doubt it. More likely than not, you're limited to the fonts on the device, at least for the iPhone. The iPad might be different, or the 3.2 SDK might expose the appropriate methods. Maybe.
Williham Totland
Ok I'll try to avoid custom fonts, thanks. So how would I feed my sql data into terminal so I can make an actual sql file to use in xcode as terminal wont take in the chinese characters.
Dave
Write an .sql file, rather than trying to type in directly, and save it as UTF-8 (I'm assuming SQLite here), then pipe that into the sqlite3 shell.
Williham Totland
Thats a really nice idea, I've managed to write the data to an .sql file but I'm not sure how to pipe the data? I think its just a few commands but I'm having a tough time trying to sort through them. Thanks again for your time
Dave
`sqlite3 database.db < file.sql` should do the trick nicely.
Williham Totland
Thank you very much :)
Dave
A: 

I've had some success using the FontLabel library. It allows you to use arbitrary .ttf fonts in your app and it's Apache-licensed:

http://github.com/zynga/FontLabel

For the majority of cases this has worked perfectly for me.

Prairiedogg
I just tried that but I seem to get square symbols where the text should be?
Dave
You might be using a font that only supports simplified or traditional characters.
Prairiedogg
A: 

I currently live in china and deal with this all of the time. Usually the problem is not the font the way the characters are represented. All unix variants use UTF-8 (most os's) Windows uses UTF-16/32 (I forget). The cool thing about UTF-8 is that it is backwards compatible with ASCII. Open your text in the text edit or firefox. In firefox you can tell the browser to try different encodings, then save it to a file. If it is the wrong in coding Mac TextEdit can convert between UTF-8 and UTF-16. Once you have the string in UTF-8 encoding you can display it in your text field.

When displaying text to a textfeild make sure an display a utf8 string not an ascii string.

If you are interested in the details of utf8, just say so and I will expand on the utf8 design.

rw

RW