Make Better Things



I like to make better things.

How to use custom fonts in iPhone

Your designer has given you a artistic font which is not available on iPhone?

Well now in iOS sdk 4 you can use any font you wish.
You just need to drag the font’s ttf file in your resource folder and do this following entry in your info.plist file –

<key>UIAppFonts</key>
<array>
        <string>CloisterBlack.ttf</string>
</array>

UIAppFonts key accept a array so you can pass multiple fonts in it.

Now wherever you want to use the font in your application you can call:

[UIFont fontWithName:@"Cloister Black" size:64.0]

Just make sure you give the real font name in above code. The font file name and its “real font name” can be different, so just open the font in FontBook app and there you can see the real name of the font.

Hope it will save someone’s time.

Category: iPhone

Tagged: , ,

5 Responses

  1. Hey Saurabh,

    Thanks for the tips!
    I was wondering, was the ‘Cloister Black’ font rendered properly on the actual device?

    Thanks!
    Borrys

    • Saurabh says:

      Hey Borrys,

      I checked “Cloister Black” font on iPod touch and iPhone 3GS and yes it was rendered properly using the above method.

      BTW: Thanks for visiting my blog…

      Regards
      Saurabh

  2. Zawmin says:

    Thanks guy.
    Yes , that real font name is important.

    Regards. :)

  3. Zawmin says:

    Hi i would like to make dictionary app for ios.
    I have above 40000 words with three column data.
    How can i import that alot of data into sqlite.
    If you know, please help me because i don’t know how to do that.
    I’m just beginner in ios.

    Thanks.

    • DenZuck says:

      To import data into a sqlite DB you need a sqlite manager such as “SQLite Manager” which is a FireFox addon or “MesaSQLite” which is a standard application. Both of them let you create tables and import data from file.

      I think SQLite Manager addon is easier to use and has more import options since it supports CSV, TAB, XML and SQL files. MesaSQLite supports import only from CSV and TAB delimited files but let you define indexes on table fields which does not work on the FireFox addon.

      All clear ?

      1) Create your DB and add a new table for word definitions
      2) Import data using one of the previous SQLite manager
      3) Add an index to the word field, that is very important in order to increase performance on search
      4) Add this DB to your XCode project, simply drag it
      5) Now you are ready to access it from your cocoa touch applications

      Regards

Leave a Reply