Custom iPhone Fonts
2010.01.16Update 2010.03.08: Apple fixed this in the upcoming 3.2 SDK update. You can supply a list of custom fonts for the key UIAppFonts in the Info.plist file and they'll be loaded from the application bundle and made available for use in your application.
The iPhone SDK (as of version 3.1.2) doesn't provide any easy way to load custom fonts.
Here's a function that will load all .ttf fonts included in your application bundle and make them available for use in your application. Unlike some other solutions I've seen (FontLabel for example), fonts loaded in this manner can be used just like built-in fonts. i.e., [UIFont fontWithName: size:] simply works as usual.
#import <dlfcn.h>
void loadFonts()
{
NSString* frameworkName = @"com.apple.GraphicsServices";
NSBundle* frameworkBundle = [NSBundle bundleWithIdentifier:frameworkName];
if (frameworkBundle)
{
const char* frameworkPath = [[frameworkBundle executablePath] UTF8String];
if (frameworkPath)
{
void* graphicsServices = dlopen(frameworkPath, RTLD_NOLOAD | RTLD_LAZY);
if (graphicsServices)
{
BOOL (*GSFontAddFromFile)(const char*) = dlsym(graphicsServices,
"GSFontAddFromFile");
if (GSFontAddFromFile)
{
NSArray* files = [[NSBundle mainBundle] pathsForResourcesOfType:@"ttf"
inDirectory:nil];
for (NSString* fontFile in files)
GSFontAddFromFile([fontFile UTF8String]);
}
}
}
}
}
Although this code is pretty safe and will likely continue to work through iPhone OS updates, it makes use of APIs that Apple might consider 'private'. Caveat emptor.
Hiding the iPhone Status Bar
2009.01.25Update 2009.06.17: Apple fixed this in the 3.0 SDK update. XCode now lists all of the iPhone specific Info.plist entries in the drop down for the key column. Status bar is initially hidden is the label for the UIStatusBarHidden key I describe below.
The iPhone status bar is the bar at the top that shows the carrier signal strength, time and battery indicator. Sometimes you want to remove this bar to get some extra real estate. Both code and configuration methods for controlling the status bar are well documented, but in the latter case, while what to change is obvious, how to change it isn't.
For configuring your iPhone application to hide the status bar, you need an entry in the Info.plist file. The entry you need to add has a key of UIStatusBarHidden and a value of true. The important thing is that it needs to be a boolean attribute. There are two ways to create an appropriate entry.
First method: You can edit your Info.plist file as a text file (by right clicking on the Info.plist file and choosing Open As > Plain Text File), and add the following entry:
<key>UIStatusBarHidden</key>
<true/>
Second method: Add an attribute in the XCode property list editor. It defaults to string types for new attributes. To change the attribute from the default string to a boolean right click the row for the attribute and choose Value Type > Boolean. Make sure you don't have a pre-defined key selected from the drop-down as it won't let you change the value type for those pre-defined keys. Also, make sure you aren't actively editing the text field, otherwise you'll get the wrong contextual menu popping up. This would be easier if the property list editor in XCode simply had another column for value type with a drop down, which is exactly how the Mac OS X property list editor works. They should've simply used that interface instead of coming up with a different interface for the XCode property list editor.
For completeness, you can hide the status bar via code by calling setStatusBarHidden:(BOOL)hidden animated:(BOOL)animated on UIApplication. The most logical place to call this is from within your UIApplicationDelegate's implementation of applicationDidFinishLaunching:.
