Sunday, December 2, 2012

Custom Fonts in an iOS App


UPDATE --  Swift 3 and Xcode make it easier than ever to add custom fonts to an iOS App. Below is the updated video for this.  Below is the original post with all the extra steps. 




ORIGINAL POST -------
In this post we are going to explore the world of custom fonts and iOS.  Now there are plenty of fonts built in but there might come a time where you know of an OTF or TTF file that has the exact font you want and is not in the choices in Xcode.  

Step 1: Find Your Font
For this app you can use any otf or ttf type file.  A few options are Font Squirrel or Smashing Magazine.  You can also use any other free fonts that a Google search turns up or you could build your own.   

Step 2: Add it to Your Xcode Project


Step 2: Use the following code snippet to find the font name.


Code Snippet
for(NSString *family in [UIFont familyNames]){
        for(NSString *font in [UIFont fontNamesForFamilyName:family]){
            if([[font lowercaseString] hasPrefix:@"w"])
            {
                printf( "Font: %s \n", [font UTF8String] );
            }
        }
    }


Step 3: Apply the Font to your Label


As Always Happy Coding
Jeremy Skrdlant