问题
I'm building an iPad-Only application. I need to use a custom font with some labels, so I added them to my project. They appear in my application target for "Copy Bundle Resources". I also added their names to my App's -Info.plist file:
<key>UIAppFonts</key>
<array>
<string>font1.ttf</string>
<string>font2.ttf</string>
<string>font3.ttf</string>
<string>font4.ttf</string>
</array>
Even so, when I try to set the font of my labels, it seems to just use the default. I haven't been able to figure out how to overcome this issue. Any assistance would be greatly appreciated.
Edit:
- (void)debug {
NSLog(@"fonts: %@", [UIFont familyNames]);
UIFont *f1 = [UIFont fontWithName:@"Helvetica" size:20];
UIFont *f2 = [UIFont fontWithName:@"font1" size:5];
NSLog(@"f1:%@ f2:%@", f1, f2);
}
And the output: http://pastie.org/1323195
回答1:
How are you setting the font?
You need to use it as follows....
UIFont *myCustomFont = [UIFont fontWithName:@"font1" size:30];
回答2:
The solution ended up being to use a different font. I opened the font with FontForge and got this warning:
This font is marked with an FSType of 2 (Restricted License). That means it is not editable without the permission of the legal owner.
This seems to be the cause of my issues. I downloaded a free version of the font I was trying to use (luckily it was available for free) and everything started working perfectly.
来源:https://stackoverflow.com/questions/4268747/custom-font-for-ipad-ios-3-2-isnt-working