IOS Add custom Font method detailed _ios

Source: Internet
Author: User

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.


@interfaceUIFont (tjcustom)

+ (Uifont *) Systemfontofsize: (cgfloat) fontsize;


#import "Uifont+custom.h"

@implementationUIFont (Tjcustom)

+ (Uifont *) Systemfontofsize: (cgfloat) fontsize


return[uifont fontwithname:@ "fzltxhk--gbk1-0" size:fontsize];



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:
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!

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.