Using custom fonts is not the most straight forward thing on the iPhone. Luckily good people at Zynga developed an easy to use FontLabel class. Download it here. Add the files to your project.
Step 1. Import the FontLabel header:
#import "FontLabel.h"
Step 2. Create a label.
//note the name of my font file is 'Rage italic.tty' FontLabel *label = [[FontLabel alloc] initWithFrame:CGRectMake(10, 10, 210, 110) fontName:@"Rage Italic" pointSize:30.0f]; //set the color label.textColor = [UIColor colorWithRed:0.254 green:0.216 blue:0.078 alpha:1]; //set the text label.text = @"Denis you're a handsome man!"; //skip the background. make it transparent label.backgroundColor = nil; label.opaque = NO; label.lineBreakMode = UILineBreakModeTailTruncation; //dynamic number of lines label.numberOfLines = 0; //text alignment label.textAlignment = UITextAlignmentCenter; //add to where you need it [myView addSubview: label]; //and release it [label release];
Tags: custom font, iPhone, zynga