UIAppFonts
,即在plist编辑器中选择 Font s provided by application这项,往里面添加item,每个item是一个ttf文件名。 UIAppFonts
( Array
- iOS) specifies any app-provided fonts that should be made available through the normal mechanisms. Each item in the array is a string containing the name of a font file (including filename extension) that is located in the app’s bundle. The system loads the specified fonts and makes them available for use by the app when that app is run
The fully specified name of the font. This name incorporates both the font family name and the specific style information for the font.
void printAllFonts()
{
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for(indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name:%@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]];
for(indFont=0; indFont<[fontNames count]; ++indFont)
{
NSLog(@"\tFont name:%@",[fontNames objectAtIndex:indFont]);
}
[fontNames release];
}
[familyNames release];
Family name:Heiti SC
Font name:STHeitiSC-Medium
Font name:STHeitiSC-Light
Family name:FZChaoCuHei-M10S
Font name:FZCCHJW--GB1-0
FZChaoCuHei-M10S 是一个自己添加的ttf字体。一般我们用family name就可以。
附加福利:在cocos builder中指定ttf字体
cocos builder中是有User Fonts这一项的,可以选择资源里面的ttf文件,但是如果你选了一个例如 font1.ttf 进去,你回发现根本没用,cocos builder自己都显示不了,游戏中也是不行。
其实也还是有办法的,就是直接将font family name作为ttf文件名,例如 FZChaoCuHei-M10S.ttf作为文件名,再在cocos builder里面选择,就可以了。
1) Font s provided by application 可以使用相对路径,把ttf/ttc字体放在bundle的子目录中,例如:res/fonts/font1.ttf
2) 使用iOS内建机制UIFont则不能把字体下载下来再使用,如果需要可使用freetype自己去实现字体的渲染