Possible Duplicate:
Custom font in iPhone
I'm trying to create a custom label to set it as a titleView
of my navigationItem
, but I'm not able to set the label font to a custom font included im my project.
I have a custom font file called "BADER_AL_GORDABIA-2_0.ttf" and the real font name as shown in FontBook is "bader_al gordabia-2" I have followed these steps:
- checked the deployment target of my app, and it is set to iOS 5.1
- added the font file to project resources, and verified that is is added to the build target in the "Copy Bundle Resources" in Build Phases.
- added a new key in my info.plist file as "Fonts provided by application", and added the "BADER_AL_GORDABIA-2_0.ttf" inside it.
- used the real font name "bader_al gordabia-2" in fontWithName method.
I was able to load the font using
UIFont * customFont = [UIFont fontWithName:@"bader_al gordabia-2" size:18.0f];
and I made sure that customFont is not null (by printing its description), but the problem is I can't apply this custom font to a UILabel.
my code is:
UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(100,10,200,24)];
titleLabel.backgroundColor = [UIColor clearColor];
UIFont * customFont = [UIFont fontWithName:@"bader_al gordabia-2" size:18.0f];
[titleLabel setFont:customFont];
titleLabel.text = @"أخبار الجمعية";
//NSLog(@"%@", [customFont description]);
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = [UIColor whiteColor];
[self.navigationItem setTitleView:titleLabel];
I have tried to search stack Overflow and I wasn't able to find a suitable answer. I have tried also to use a custom label as specified in the following link: http://refactr.com/blog/2012/09/ios-tips-custom-fonts/