Archive for February 26th, 2013

Custom fonts in XCode and iOS

If you are having problems adding custom fonts to XCode for use in iOS projects, ensuring that you’ve added them to the projects resources, have correctly referenced their filename in the project’s .plist file and setup your custom font with:

UIFont *customfont = [UIFont fontWithName:@"font name" size:16]

If it’s still not working then check the string you’re using for the font. It has to match what font name XCode has for the font, not the font’s name or even what Font Book says the name is for the font. Here’s an easy way to log all of the fonts included in your project and therefore use the correct reference:

for ( NSString *familyName in [UIFont familyNames] ) { NSLog(@"Family %@", familyName); NSLog(@"Names = %@", [UIFont fontNamesForFamilyName:familyName]); }

Easy.

Here’s some more discussions on Stack Overflow with various other problems and solutions.