1: Get font file
Download font files from various channels TTF, website or from other IPA to buckle out. (Take Fzltxh.ttf as an example)
2: Copy the Fzltxh.ttf file to the project
3: Add the item in Info.plist:
Fonts provided by Application (uiappfonts) can add one or more item,
such as ITEM0--Fzltxh.ttf
4: Find out the real font name:
Because when using fonts, to use the real name of the font, rather than the file name, you can use the following code to traverse the font names available for the current device.
Then find 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 of this font.
5: Using Fonts
[Uifont fontwithname:@ "fzltxhk--gbk1-0" size:fontsize];
6: Unified 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.
uifont+custom.h// tujing//// Created by Willbin on 15/1/13.// Copyright (c) 2015 Willbin. All rights reserved.//#import <UIKit/UIKit.h> @interface Uifont (tjcustom) + (Uifont *) Systemfontofsize: (cgfloat) FontSize; @end
uifont+custom.m// tujing//// Created by Willbin on 15/1/13.// Copyright (c) 2015 Willbin. All rights reserved.//#import "Uifont+custom.h" @implementation Uifont (Tjcustom) + (Uifont *) Systemfontofsize: (cgfloat ) fontsize{ return [Uifont fontwithname:@ "fzltxhk--gbk1-0" size:fontsize];} @end
In that case, the original writing
The Systemfontofsize method is replaced by a new method, which results in an overall substitution.
iOS Add custom font methods