Get ready:
Font file (. ttf,.odf)
Method 1:
Add the corresponding font (. ttf or. odf) to the resurce of the project, use the Fontlabel library in cocos2d, Fontlabel inherit the Uilabel, and use it like a Uilabel
FontName directly using the added resource name
Method 2:
1. Add the corresponding font (. ttf or. odf) to the resurce of the project, such as My.ttf
2. Add a Fonts provided by application in Info.plist (item0 corresponding value is My.ttf, add multiple fonts to add it in turn)
3. When using Alabel.font=[uifont fontwithname:@ "XXX" size:30]; Note that XXX is not necessarily my, here is return to CASTLE,
Family Name:return to CASTLE
Font Name:returntocastle
Double-click, Mac under the title bar of the window under the font family name,windows can display family name and font name, the following sentence with family name and font name can be
Self.labelTest1.font = [Uifont fontwithname:@ "RETURN to CASTLE" size:30];
You can also traverse all fonts in the following ways:
Here is the code snippet:
Stupid way: Print out the fonts, look for non-system fonts ... (A very non-language method)
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 (@ "Font name:%@", [FontNames Objectatindex:indfont]);
}
[FontNames release];
}
[Familynames release];
In the program to first add this code, run, view console, the above program will list all the fonts, of course, also contains the font added by uiappfonts, but please note that the name may be very large gap, to find their own, not the font of the file name, the mistake will not see the effect.