1: Get the font file
Download font files from a variety of sources TTF, website or from other IPA. (Take Fzltxh.ttf as an example)
2: Copy the Fzltxh.ttf file to the project
3: Add items to Info.plist:
Fonts provided by Application (uiappfonts) can add one or more item,
such as ITEM0--Fzltxh.ttf
4: Find the Real font name:
Because using fonts, you use the real name of the font instead of the filename, you can use the following code to traverse the font name available for the current device.
and find out the real name of the font you just added.
Nsarray*familynames = [Uifont familynames];
For (Nsstring*familyname in familynames)
{
printf ("Family:%s \ n", [Familyname utf8string]);
Nsarray*fontnames = [Uifont fontnamesforfamilyname:familyname];
For (Nsstring*fontname in FontNames)
{
printf ("\tfont:%s \ n", [FontName utf8string]);
}
Fzltxhk--gbk1-0 This is the real use name for this font.
5: Using Fonts
[Uifont fontwithname:@ "fzltxhk--gbk1-0" size:fontsize];
6: Uniform replacement
If you want to replace the old project font as a whole, and do not want to change the existing code, you can rewrite
Systemfontofsize method.
#import
@interfaceUIFont (tjcustom)
+ (Uifont *) Systemfontofsize: (cgfloat) fontsize;
@end
#import "Uifont+custom.h"
@implementationUIFont (Tjcustom)
+ (Uifont *) Systemfontofsize: (cgfloat) fontsize
{
return[uifont fontwithname:@ "fzltxhk--gbk1-0" size:fontsize];
}
@end
In this case, originally written
The Systemfontofsize method replaces the new method, thus achieving the overall substitution effect.
Text/Left hand (Jane book author)
Original link: http://www.jianshu.com/p/edf51b8b6479
Copyright belongs to the author, reproduced please contact the author to obtain authorization, and labeled "Jane book author."
Above is the iOS adds the custom font method The data collation, the follow-up continues to supplement the related information, thanks everybody to this website support!